2012-07-14 52 views
0

我觉得很愚蠢,但我无法理解如何将数据分配给博客教程中的视图(编辑帖子表单)。我不明白CakePHP博客教程的Edit部分中发生了什么

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html#editing-posts

public function edit($id = null) { 
$this->Post->id = $id; 
if ($this->request->is('get')) { 
    $this->request->data = $this->Post->read(); 

所以这是request->data阵列从数据库中的一些数据分配,对不对? 但是,视图如何在表单域中获取这些数据?

P.S.为什么null被用作edit($id = null)的默认值?

回答

0

您分配给控制器中的$ this-> request-> data的任何内容都将在您的视图中显示为$ this-> data。如果您使用表单助手中构建的蛋糕,那么可以非常聪明地检查$ this-> data以获取与您的表单控件的名称相匹配的变量。

+0

谢谢。现在我终于想出了这个魔法。 – user1327 2012-07-14 16:09:45

相关问题