目前正在尝试使用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() {
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')),
);
}
答案 0 :(得分:1)
$this
是PHP中的预定义变量,它已经有一个值,您无法对其进行更改。您可以使用$this
仅操纵当前对象。
有关对象的更多信息(以及$this
可能的内容),请访问:http://php.net/manual/en/language.oop5.basic.php
答案 1 :(得分:1)
你走了。只需使用$ this-> set(compact());并包含要传递给视图的变量列表。
$ this-> set(compact(' users','地址'));