Cakephp Parse错误:语法错误,意外的'Class'(T_CLASS),期望标识符(T_STRING)

I have a table named 'classes' in my database.

When I do a cake bake all classes I'm getting this error:

Parse error: syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING) in C:\xampp\htdocs\timetable\src\Model\Table\ClassesTable.php on line 4

I understand where the error is coming from, but is there a way to get rid of this error without having to rename my 'Classes' table?

Class is a reserved keyword of PHP, and will cause trouble if you instantiate it as such.

A solution would be to manually create a Model as thus:

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

You need to ensure that your controller $uses MyClass (inside your ClassesController).

After that, the Model should be usable as any other, despite the reserved term. Having said that, I am not 100% on the results of a bake once you've manually created the Model, so please, if you could post your results, that would be great.

I understand where the error is coming from, but is there a way to get rid of this error without having to rename my 'Classes' table?

No you don't. :) The issue happens because CakePHP tries to bake \App\Model\Entity\Class.php which is obviously not going to work. The issue is not the table class name.

You will have to name the entity class somehow different and tell your table object to work with that entity class. This happens because Cake expects the entity to be singular by convention and "class" is a reserved key word in php. Cake inflects "Classes" to singular for the entity and thats causing the issue. So bake your model, change the entity class, then bake the controller and views.

I recommend you to read and remember the CakePHP conventions.