CakePHP:语法错误,意外的T_LIST,期待T_STRING

Kos*_*tos 3 cakephp syntax-error

我的cakephp应用程序在那一行上抛出了我的错误:

class List extends AppModel {
Run Code Online (Sandbox Code Playgroud)

我无法理解为什么.

整个List.php模型文件是:

<?php

App::uses('AuthComponent', 'Controller/Component');
class List extends AppModel {

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
    }
    return true;
}
?>
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么会这样?

谢谢!

tha*_*tah 13

List是PHP中的保留关键字

您收到此错误,因为它list是PHP中的保留关键字,因此不能用作您的类的名称;

http://php.net/manual/en/reserved.keywords.php

将您的模型重命名为其他内容,您应该没问题.要仍然使用相同的数据库表,请通过useTable属性手动指定模型使用的数据库表;

class MyList extends AppModel
{
    public $useTable = 'lists';
}
Run Code Online (Sandbox Code Playgroud)