0
我正在努力学习Drupal 8.所以现在,我正在“构建”表单。 我创建了一个模块。 INSIDE mymodule中的\ src \表 我form1.phpdrupal_set_title不能以模块形式工作
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,
);
...
我收到以下错误:
错误: 致命错误:调用未定义的函数的Drupal \ mymo用C独乐\表格\ drupal_set_title():\ XAMPP \ htdocs中\ drupalwebsite \模块\定制\ MyModule的\ SRC \表格\ form1.php第16行
的线16是:
drupal_set_title(t('This is a Title'));
所以问题出在标题上。我试图解决它,但我不能。 任何人都知道为什么? 非常感谢
你让我很快乐!我不知道为什么我读的书会混合6/7/8。非常感谢! – Peter