CakePHP以表格形式输入$变量
问题描述:
我正在使用CakePHP 2.3.1。
我需要知道是否有可能在表单字段中填充$ variable。 如果(存在)我应该怎么做?
正如你可以在我的event_repeat()函数中看到的。
function repeat($id = null) {
if (!$id) {
$this->Session->setFlash(__('Prenotazione non trovata'));
$this->redirect(array('action' => 'view', $this->data['Event']['id']));
}
//this is the variable I need
$repeat = $this->data['Event']['repeat'];
$i = 1;
do {
//code
} while ($repeat > $i);
}
$ repeat变量,是用户需要的重复次数,我希望它通过输入形式设置为正整数值。
如何使输入字段引用控制器内的变量而不是数据库字段?
答
在你看来:
print $this->Form->input('repeat', array('label' => 'How many times you wish to repeat?', 'name' => 'data[repeats]'));
而在你的控制器:
$repeats = $this->data['repeats'];
+0
谢谢你的工作;) – 2013-04-12 11:23:50
你是什么意思?设置表单域的默认值? – 2013-04-09 15:16:42
不,我需要输入字段直接指向控制器中的那个变量,它不是数据库字段。例如:'$ this-> Form-> input('repeat',array('label'=>'你想重复多少次?'));' – 2013-04-09 15:21:13