You are here

Strict warning: Only variables should be passed by reference 在 contactus_page()报错,看不懂了。

moumouguoguo 的头像
Submitted by moumouguoguo on 星期一, 2013-09-02 03:19

启用这个模块后,再访问127.0.0.1/?q=contactus,还要报Strict warning: Only variables should be passed by reference 在 contactus_page() (行 28D:\WWW\drupal\sites\all\modules\custom\contactus\contactus.pages.inc).这种错误,而且页面上不显示表单,但我用kpr方法可以打印表单项,这是为什么呢?

contactus.module文件

/**
 * Implements hook_menu().
 */
function contactus_menu() {
    $items ['contactus'] = array (
            'title' => '联系我们',
            'description' => '这是悬浮提示',
            'page callback' => 'contactus_page',
            'type' => MENU_CALLBACK,
            'access callback' => TRUE,
            'file' => 'contactus.pages.inc'
    );
    $items ['contactus/confirm'] = array (
            'page callback' => 'contactus_confirm_page',
            'type' => MENU_CALLBACK,
            'access callback' => TRUE,
            'file' => 'contactus.pages.inc'
    );
    //致谢页面的菜单
    $items ['contactus/thanks'] = array (
            'page callback' => 'contactus_thanks_page',
            'type' => MENU_CALLBACK,
            'access callback' => TRUE,
            'file' => 'contactus.pages.inc'
    );
    return $items;
}

contactus.pages.inc文件代码

function contactus_page() {
    drupal_set_title ( '联系我们' );
    $render_array = array (
            '#makeup' => '',
    );
    $render_array['#makeup']  .= drupal_render ( drupal_get_form ( 'contactus_form' ) ) ;
    kpr($render_array);  //这里可以打印表单
    return $render_array;
}

function contactus_form() {
    $form ['tips'] = array (
            '#prefix' => '<div id="tips">',
            '#makeup' => t ('<span class="form-required">*</span>号为必填项'),
            '#suffix' => '</div>',
    );
    $form ['name'] = array (
            '#title' => t('姓名'),
            '#type' => 'textfield',
            '#required' => TRUE,
            '#default_value' => isset($_SESSION['contactus_form']['name'])?$_SESSION['contactus_form']['name']:'',
            '#description' => t('例如:周星弛'),
    );
    return $form;
}

论坛:

Drupal版本:

g089h515r806 的头像

这个不影响工作

PHP版本的问题,有的PHP版本下,比较低的版本,是不会有这个警告信息的。

 
解决的办法是这样的:

$render_array['#makeup']  .= drupal_render ( drupal_get_form ( 'contactus_form' ) ) ;
应该这样写:
$contactus_form =drupal_get_form ( 'contactus_form' );
$render_array['#makeup']  .= drupal_render ($contactus_form) ;