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

报告相同问题?

悬赏问题

  • ¥60 QQOP数据,什么是op数据号,怎么提取op数据!能不能大量提取(语言-c语言)
  • ¥15 matlab代码 关于微分方程和嵌套的分段函数。
  • ¥15 把VMware项目复制到另一台电脑
  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密