Question

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 ?

Was it helpful?

Solution

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.

OTHER TIPS

I can't remember the name I used but I had a similar issue with cakephp and after some looking online it worked out to be so much easier to just change the table name. The naming conventions are quite strict and creating a work-around for this isn't worth it.

You could find a different name for your model and then link that model to your table using useTable

hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top