dongre9937 2014-02-12 20:25
浏览 37
已采纳

如何在CakePHP的输入字段中显示数据库中的值

I liked to know how I can show a value from my database into an input field. I'm working with CakePHP.

Right now, I have some empty fields, but I want them filled with the database values when I display my page the first time and of course when there are values in the database relative to these fields. I'm able to retrieve all my database data, but unable to show them into the fields.

Is there an easy way with CakePHP to do it or I need to set each field individually in my controller and retrieve it in my view.

Thank you

  • 写回答

1条回答 默认 最新

  • doujiao1180 2014-02-12 20:34
    关注

    You are able to fill forms from the controller, by using $this->form->data.

    Example:

    $this->request->data = $this->YourModel->findById($id);
    

    Edit:

    You have to create your form with the form helpers to attach the form to your model, otherwise it won't work.

    echo $this->Form->create('YourModel');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?