【问题标题】:CakePHP input a $variable in a formCakePHP 在表单中输入一个 $ 变量
【发布时间】:2013-04-09 15:11:07
【问题描述】:


我正在使用 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 变量,是用户想要的重复次数,我希望通过输入表单将其设置为正整数值。

如何让输入字段引用控制器内部的变量,而不是数据库字段?

【问题讨论】:

  • 什么意思?设置表单域的默认值?
  • 不,我需要输入字段直接引用控制器中的该变量,这不是数据库字段。表单示例:$this->Form->input('repeat', array('label' => 'How many times you wish to repeat?'));

标签: forms cakephp variables do-while cakephp-2.3


【解决方案1】:

在你看来:

print $this->Form->input('repeat', array('label' => 'How many times you wish to repeat?', 'name' => 'data[repeats]'));

在你的控制器中:

$repeats = $this->data['repeats'];

【讨论】: