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

时间:2013-05-10 20:54:54

标签: cakephp syntax-error

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

class List extends AppModel {

我无法理解为什么。

整个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;
}
?>

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

谢谢你!

1 个答案:

答案 0 :(得分:12)

List是PHP中的保留关键字

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

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

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

class MyList extends AppModel
{
    public $useTable = 'lists';
}