2014-04-11 42 views
0

我正在嘗試將自定義主題應用於單個頁面。該頁面是我使用hook_menu設置的頁面。 我已經impletemted hook_theme但是當我刷新網頁,我收到以下錯誤:Drupal hook_theme錯誤

Fatal error: Unsupported operand types in /srv/bindings/baf029321aa248e5907866cc7de3a6d6/code/includes/form.inc on line 1044

以下是我的代碼:

function mymodule_menu(){ 
    $items['mymodule'] = array(
     'title' => 'My-module', 
     'page callback' => 'drupal_get_form', 
     'page arguments' => array('mymodule_admin_page'), 
     'access arguments' => array('access content'), 
    ); 
    return $items; 
} 

function mymodule_admin_page(){ 
    drupal_set_message('My-module admin page responding'); 

    return theme('mymodule_template'); 
} 

function mymodule_theme($existing, $type, $theme, $path){ 
    drupal_set_message('My-module theme hook responding'); 

    return array(
     'mymodule_template' => array(
      #'render element' => 'elements', 
      'template' => 'mytemplate', 
      'path' => drupal_get_path('module', 'mymodule') . '/templates', 
     ) 
    ); 
} 

至於我可以告訴大家,出現錯誤時,我將正斜槓添加到'path' => drupal_get_path('module', 'mymodule') . '/templates',。 如果我刪除斜槓錯誤消失,但然後系統嘗試並找不到mytemplate.tpl.php,因爲它正在查看mymodule/templatemytemplate.tpl.php

+0

移動'drupal_get_path( '模塊', 'MyModule的')。 '/ templates'到另一個變量,然後在''path'=> $ myVariable'中使用它 –

回答

0

嘗試...... 這個菜單alwaya調用形式函數不能調用一個主題功能

$items['mymodule'] = array(
     'title' => 'My-module', 
     'page callback' => 'drupal_get_form',//this is use a get the form 
     'page arguments' => array('contactform_form'),// this is use a name of form 
     'access arguments' => array('access content'), 
); 

function contactform_form($form, &$form_state) 
{ 
    //write a form attributes 
}