Php 致命错误,无法重新签名
目前正在尝试使用CakePHP查找要填充两个列表的项,但我遇到了这个错误。我对PHP和CakePHP尤其陌生,但我认为我的数组可能有问题Php 致命错误,无法重新签名,php,cakephp,Php,Cakephp,目前正在尝试使用CakePHP查找要填充两个列表的项,但我遇到了这个错误。我对PHP和CakePHP尤其陌生,但我认为我的数组可能有问题 Error: Cannot re-assign $this File: /var/www/vhosts/toast.lancs.ac.uk/httpdocs/jahans/Wimbrick/app/Controller/CompaniesController.php Line: 75 以下是导致问题的函数: public function add()
Error: Cannot re-assign $this
File: /var/www/vhosts/toast.lancs.ac.uk/httpdocs/jahans/Wimbrick/app/Controller/CompaniesController.php
Line: 75
以下是导致问题的函数:
public function add() {
if ($this->request->is('post')) {
$this->Company->create();
if ($this->Company->save($this->request->data)) {
$this->Session->setFlash(__('The company has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The company could not be saved. Please, try again.'));
}
}
$users = array(
'User' => $this->Company->User->find('list'),
'Address' => $this->Company->User->find('list'));
$this = array(
'users' => set(compact('users')),
'addresses' => set(compact('addresses')),
);
}
$this
是PHP中预定义的变量,它已经有一个值,您不能更改它。您可以使用$this
仅操纵当前对象
有关对象的更多信息(以及使用
$this
可以实现的功能)请访问:点击这里。只需使用$this->set(compact());并包括要传递给视图的变量列表
$this->set(压缩(“用户”、“地址”)
$this=array(
…您试图在这里分配什么?这些数组元素打算在$this
中修改哪些属性?@MichaelBerkowski我正在尝试设置多个$this->set(compact('users'));
我应该使用更像$findr=array('users'=>$this->set(compact('users'))的数组吗,'addresses'=>$this->set(compact('addresses'),);
取而代之的是?所以您试图调用$this->set(compact('key'))
来查找数组('users','addresses')中的所有键。
?(对不起,我不太了解CakePHP惯例)@MichaelBerkowski与此类似,我正在尝试查找每个表的id,该表在函数前面引用过。感觉如此接近!唯一的问题是地址
来自不同的表,那么我如何引用它呢?我尝试了:$users=$this->Company->User->find('list'))
$addresses=$this->Company->Address->find('list');
$this->set(compact('users','addresses'));
但它不起作用。