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 Answers
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.
1 Comment
AD7six
may -> it does (it's a parse error - as also mentioned in the question). Worth mentioning associations can be aliased
$hasMany => array('Class' => array('className' => 'MyClass')); +1 for including an example.You could find a different name for your model and then link that model to your table using useTable
hope that helps