【问题标题】:Drupal hook_theme errorDrupal hook_theme 错误
【发布时间】:2014-04-11 14:03:30
【问题描述】:

我正在尝试将自定义主题应用于单个页面。该页面是我使用 hook_menu 设置的。 我已经实现了 hook_theme,但是当我刷新网站时,我收到以下错误:

致命错误:第 1044 行 /srv/bindings/baf029321aa248e5907866cc7de3a6d6/code/includes/form.inc 中不支持的操作数类型

以下是我的代码:

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

【问题讨论】:

  • drupal_get_path('module', 'mymodule') . '/templates'移动到另一个变量,然后在'path' => $myVariable中使用它

标签: drupal-7 hook-theme


【解决方案1】:

试试这个... 这个菜单总是调用表单函数而不是主题函数

$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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多