如何从窗体(视图)中的文本框中检索值到cake php中的控制器?
答案 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