如何在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
我想知道如何将数据库中的值显示到输入字段中。 我正在使用CakePHP。 p>
现在,我有一些空字段,但是当我第一次显示页面时,我希望它们填充数据库值,当然还有 数据库中与这些字段相关的值。 我能够检索我的所有数据库数据,但无法将它们显示在字段中。 p>
CakePHP是否有一种简单的方法可以执行此操作,或者我需要单独设置每个字段 我的控制器并在我的视图中检索它。 p>
谢谢 p> div>
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');