CakePHP:编辑屏幕中没有填充的字段
问题描述:
来自绝对n00b的简单问题。CakePHP:编辑屏幕中没有填充的字段
我正在尝试基于Cake网站上的博客教程中给出的代码创建一个编辑内容屏幕。
这里的控制器(它的命名内容)我的编辑功能:
function edit($id = null) {
$this->Content->id = $id;
Debugger::dump($this->Content->id);
if(empty($this->data)) {
$this->data = $this->Content->read();
Debugger::dump($this->Content);
}
else {
if($this->Content->save($this->data)) {
$this->Session->setFlash('Content has been updated.');
$this->redirect(array('action' => 'index'));
}
}
}
这是edit.ctp:
echo $form->create('Content', array('action' => 'edit'));
echo $form->input('id', array('type' => 'hidden'));
echo $form->input('title');
echo $form->input('nicename');
echo $form->end('Save');
然而,当我参观编辑屏,输入字段不会与请求的数据一起获得信息。
我使用HTML辅助生成的链接和我的编辑链接的格式如下:
http://localhost/contents/edit/id:4c8efaa0-02fc-46bf-ac65-06a07614f57d
正如你所看到的,我推出了两种调试器在控制器的编辑功能转储...那些显示$ this-> Content-> id在我访问此URL时保持为NULL。
但是,如果我修改URL以这种形式(请注意,我用'='代替':'):
http://localhost/contents/edit/id=4c8efaa0-02fc-46bf-ac65-06a07614f57d
调试报告$这个 - >内容 - >编号以具有正确的值...
但是,我的领域仍然没有得到填充。
索引功能工作正常,但...
function index() {
$this->set('contents', $this->Content->find('all'));
}
上述功能是否正确列出的内容!
我哪里错了?我是否错过了View中的一些重要代码? 任何帮助将不胜感激。
感谢, 平方公尺Ë
答
的问题是在这里:
http://localhost/contents/edit/id:4c8efaa0-02fc-46bf-ac65-06a07614f57d
基本上您的网址应该是这样的:
http://localhost/contents/edit/4c8efaa0-02fc-46bf-ac65-06a07614f57d
正如你可能会注意到ID:从失踪正确的网址。原因是:如果你传递了id:这是命名参数,它没有被分配给函数中的$ id。
您的链接编辑表单应该是这样的:
$this->Html->link('Edit', array('controller'=>contents', 'action'=>'edit', $id_variable));
谢谢聂。在等待答复时,我决定完全重新编写代码并重新开始......并且通过检查脚手架生成的链接,我得出了与您的结论相同的结论。 – 2010-10-08 15:56:26
嗯..仍然有链接生成问题..这里是我的代码:echo $ html-> link('Edit',array('controller'=>'contents','action'=>'edit','id'=> $ item ['Content'] ['id'])); – 2010-10-08 16:00:52
然后......没关系..想通了。它应该是:echo $ html-> link('Edit',array('controller'=>'contents','action'=>'edit',$ item ['Content'] ['id'])) – 2010-10-08 16:02:55