注意事项(8):未定义变量 cakePHP 3
Notice (8): Undefined variable cakePHP 3
在网上搜索了好几个小时后,我决定post在这里提出我的问题,希望能找到解决方案
这是我视图中的代码 add_by_complex.ctp
:
<div class="immeubles form large-10 medium-9 columns content">
<?= $this->Form->create($immeuble); /* line 9 */ ?>
<fieldset>
<legend><?= __('Ajouter un immeuble') ?></legend>
<?php echo $this->Form->input('name',['label' => 'Nom']); ?>
</fieldset>
<?= $this->Form->button(__('Valider')) ?>
<?= $this->Form->end() ?>
</div>
这是错误信息:
Notice (8): Undefined variable: immeuble
[APP/Template\Immeubles\add_by_complex.ctp, line 9]
有什么问题?非常感谢
使用上下文创建表单时,您必须向 create()
方法表单提供实体或 ArrayContext。
The $model argument is used as the form’s ‘context’. There are several built-in form contexts and you can add your own, which we’ll cover in the next section. The built-in providers map to the following values of $model:
http://book.cakephp.org/3.0/en/views/helpers/form.html#starting-a-form
如果您不提供任何参数,它会假定您只是构建一个提交给控制器的表单。
要能够访问视图中的实体或任何其他变量,您必须set the View variable
在网上搜索了好几个小时后,我决定post在这里提出我的问题,希望能找到解决方案
这是我视图中的代码 add_by_complex.ctp
:
<div class="immeubles form large-10 medium-9 columns content">
<?= $this->Form->create($immeuble); /* line 9 */ ?>
<fieldset>
<legend><?= __('Ajouter un immeuble') ?></legend>
<?php echo $this->Form->input('name',['label' => 'Nom']); ?>
</fieldset>
<?= $this->Form->button(__('Valider')) ?>
<?= $this->Form->end() ?>
</div>
这是错误信息:
Notice (8): Undefined variable: immeuble
[APP/Template\Immeubles\add_by_complex.ctp, line 9]
有什么问题?非常感谢
使用上下文创建表单时,您必须向 create()
方法表单提供实体或 ArrayContext。
The $model argument is used as the form’s ‘context’. There are several built-in form contexts and you can add your own, which we’ll cover in the next section. The built-in providers map to the following values of $model:
http://book.cakephp.org/3.0/en/views/helpers/form.html#starting-a-form
如果您不提供任何参数,它会假定您只是构建一个提交给控制器的表单。
要能够访问视图中的实体或任何其他变量,您必须set the View variable