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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog