【发布时间】:2016-02-08 17:22:23
【问题描述】:
我正在尝试学习 Drupal 8。所以现在,我正在“构建”表单。 我创建了一个模块。 在 mymodule\src\Form 里面 我有form1.php
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class form1 extends FormBase {
public function getFormId() {
return 'myform1';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 30,
);
$form['Lastname'] = array(
'#type' => 'textfield',
'#title' => t('Your lastname'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
而且工作... 但是当我想给页面加上标题时,在我的例子中并使用
链接到 my_module.routing.yml, 127.0.0.1/form1...
public function buildForm(array $form, FormStateInterface $form_state) {
drupal_set_title(t('This is a Title'));
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 30,
);
...
我收到以下错误:
错误: 致命错误:在第 16 行调用 C:\xampp\htdocs\drupalwebsite\modules\custom\mymodule\src\Form\form1.php 中未定义的函数 Drupal\mymodule\Form\drupal_set_title()
第 16 行是:
drupal_set_title(t('This is a Title'));
所以问题出在标题上。我试图解决它,但我不能。 有谁知道为什么? 非常感谢
【问题讨论】:
标签: drupal drupal-modules drupal-8