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 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下