我是Phalcon框架的初学者,我必须验证NOT NULL
页面中的表单元素
我有一个表单类文件,我在其中编写隐藏文件以进行记录编辑,我在编辑模式下将记录的id存储在隐藏文件中
.volt
问题在于我在if ($options["edit"] == 1) {
// $tax_categories_id = new Hidden("tax_categories_id");
$this->add(new Hidden('tax_categories_id'));
//$this->add($tax_categories_id);
}
add.volt
它在编辑模式下工作正常,但在新的记录时间中它给出了错误
Phalcon \ Forms \ Exception:ID = tax_categories_id的元素不是表单的一部分
我知道错误即将发生但我无法在 {{ form.render('tax_categories_id')}}
文件中验证此字段
答案 0 :(得分:1)
在控制器中你可以设置你的$ options变量,然后在视图里面检查它吗?
//controller.php
$this->view->setVar('options', $options);
//view.volt
{% if options['edit'] %}
{{ form.render('tax_categories_id')}}
{% endif %]
答案 1 :(得分:1)
只检查元素是否存在
// add.volt
{% if form.has('tax_categories_id') %}
{{ form.render('tax_categories_id') }}
{% endif %}