开发者

To retrieve value from a text box in a form (view) to controller in cake php

How to o retrieve value from a text box in a form (v开发者_如何学Goiew) to controller in cake php?


Here's an example from the CakePHP book on saving your Model data:

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));
}

If your model was Recipe, and your input was named "title", then the value would be in $this->data['Recipe']['title'], if you setup your view like so:

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

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

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

So, look here: http://book.cakephp.org/view/1031/Saving-Your-Data

And try to do the Blog tutorial, it might help you get started: http://book.cakephp.org/view/1528/Blog

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜