Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在控制器中从视图接收到的 $this->data 中设置值。
我们可以使用 if($this->data['id']) 但为什么我们不能在其中设置值?
这行得通吗$this->data['id']=$userid;
$this->data['id']=$userid;
你有几个选择
首先是创建自己的变量并修改它:
$myData = $this->data; $myData['id'] = $userid; $this->Post->save($myData);
第二种是使用$this->request->data。它包含与 $this->data 相同的信息,但可以修改。
$this->request->data['id'] = $userid; $this->Post->save($this->request->data);