doujingqu3030 2013-07-26 05:51
浏览 28
已采纳

在cakephp中使用模型类名“Class”

I have table name "classes" in database and when i create model with name "Class" ,it gives syntax error (obviously).Is there any way to remove this error without changing name of table in database ?

  • 写回答

3条回答 默认 最新

  • douyan1321 2013-07-29 14:16
    关注

    I would stay away from a model named "Class", it is a keyword of php and it may will (as pointed by @AD7six) cause trouble if instantiated like that.

    You can do the following:

    class MyClass extends AppModel {
        public $useTable = 'classes';
    }
    

    Be sure that the controller ClassesController calls MyClass (with $uses), but besides that, you can use the model like any other model without worrying about reserved keywords.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?