从表单(视图)中的文本框中检索值到蛋糕php中的控制器

时间:2010-06-15 15:08:56

标签: php cakephp

如何从窗体(视图)中的文本框中检索值到cake php中的控制器?

1 个答案:

答案 0 :(得分:0)

以下是关于保存模型数据的CakePHP书中的一个示例:

function edit($id) {
    //Has any form data been POSTed?
    if(!empty($this->data)) {
        //If the form data can be validated and saved...
        if($this->Recipe->save($this->data)) {
            //Set a session flash message and redirect.
            $this->Session->setFlash("Recipe Saved!");
            $this->redirect('/recipes');
        }
    }

    //If no form data, find the recipe to be edited
    //and hand it to the view.
    $this->set('recipe', $this->Recipe->findById($id));
}

如果您的模型是Recipe,并且您的输入被命名为“title”,则该值将在$ this-&gt; data ['Recipe'] ['title']中,如果您设置了如下所示的视图:< / p>

echo $this->Form->create('Recipe');

echo $this->Form->hidden('id');
echo $this->Form->input('title');

echo $this->Form->end('Save Recipe');

所以,请看这里:http://book.cakephp.org/view/1031/Saving-Your-Data

尝试执行博客教程,它可能会帮助您入门:http://book.cakephp.org/view/1528/Blog