天天看點

Drupal 7 自定義頁面如何向自定義的主題傳參

根據 https://www.drupal.org/node/1560952 的介紹,我自定義了一個頁面内容如下,資料都取到了,現在問題是資料沒有按着執行個體傳到主題變量中。

<?php
function metest_theme(){		
	return array(
		'metest'=>array(
			'variables'=>array('output'=>null),
			'template'=>'metest',
		),
	);
}

 function metest_menu(){
	$items=array();		
	$items['rfid/showme']=array(
		'title'=>t('ME'),		
		'description'=>t('ME'),
		'page callback' => 'metest_page',
		'access callback'=>TRUE,
			
	);
	$items['rfid-showme/%/%']=array(
		'title'=>t('ME'),		
		'description'=>t('ME'),
		'page callback' => 'metest_page_results',
		'page arguments'=>array(1,2),		
		'access callback'=>TRUE,
			
	);
	
	return $items;	
} 

function metest_page(){	
	/* $dis=drupal_get_form('metest_kanban_form');
	return $dis; */	
	return array('#markup'=>t('請選擇左邊欄'));
}

function metest_page_results($pro_date,$pro_line){
	$output=metest_get_me_result($pro_line,$pro_date);
	dpm($output);
	return theme('metest',array('output'=>$output));
}

function metest_block_info() {
  $blocks = array();
  $blocks['mekanban'] = array(
    'info' => t('ME'), 
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

function metest_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'mekanban':
      $block['subject'] = t('ME');
      $block['content'] = drupal_get_form('metest_kanban_form');
    break;	
	}
  return $block;
}
function metest_kanban_form($form, &$form_state){
	global $user;	
	$options=metest_kanban_get_lines();	
	$date_format='Y-m-d';	
	$form=array();	
	
	$pro_line=variable_get('me_pro_line'.$user->uid,$pro_line);
	$form['linelist']=array(
		'#prefix'=>'<span class="right_arrow"></span>',
		'#type'=>'select',
		'#size'=>10,		
		'#empty_option' => t('選擇組'),		
		'#options' => $options,
		'#default_value'=>$pro_line,
	 );	
	 $form['productiondate']=array(
		'#type'=>'date_popup',		
		'#title'=>t('選擇日期'),
		'#default_value'=>variable_get('me_pro_date'.$user->uid,date('Y-m-d')),	
		'#date_format'=>$date_format,
		'#date_label_position'=>'within',
		'#date_timezone'=>'Asia/Shanghai',
		'#date_increment'=>60,
		'#date_year_rang'=>'-3:+3',		
	);
	 $form['submit']= array(
		'#type' => 'submit',
		'#value' => t('送出'),				
	);	
	 return $form;
}

function metest_kanban_get_lines(){
	$options=array();
	$results=taxonomy_get_tree(12); 	
	foreach($results as $term ){
		$key=$term->tid;
		$value=$term->name;
		$term_load=taxonomy_term_load($term->tid);			
		$options[$key]=$value;		
	}
	return $options;
}

function metest_kanban_form_submit($form, &$form_state){
	$linelist=$form_state['values']['linelist'];
	$productiondate=$form_state['values']['productiondate'];	
	if(!empty($linelist)&& !is_null($productiondate)){
		global $user;
		variable_set('me_pro_date_'.$user->uid,$productiondate);
		variable_set('me_pro_line_'.$user->uid,$linelist);			
		drupal_goto(file_create_url('/rfid-showme/'.$productiondate.'/'.$linelist));
		
	}
}

function metest_get_me_result($line,$prodate){
		
		$query=db_select('node','n');
		//...
		$query->OrderBy('n.created','DESC');
		$result=$query->execute()->fetchAll();	 	
		return $result;
}
           

在metest.tpl.php中讀$output,但沒有成功,不知道是何原因,模闆檔案放在jean自定義的主題檔案夾内../jean/template/metest.tpl.php

<?php dpm($output);?>
           

此圖是 metest_page_results()中的dpm輸出的調試,說明資料取到了,現在最關鍵就在後面的theme()沒有傳遞成功。

Drupal 7 自定義頁面如何向自定義的主題傳參