Beginner issue on "bin/cake bake model users"

Helloh!

I’m new to this forum thingy so plz don’t be mad if I can’t put stuff into code blocks.
I just installed CakePHP, now I am following the CMS tutorial: CMS Tutorial - Creating the Articles Controller - 4.x

I got to page 3 (“Tags and Users”) where it tells me to bake, then I get an error in “ArticlesTable.php” which I don’t understand:
bin/cake bake model users
One moment while associations are detected.
Exception: syntax error, unexpected ‘public’ (T_PUBLIC), expecting end of file
In [/var/www/clients/client4/web8/web/cms3021/src/Model/Table/ArticlesTable.php, line 12]

2021-03-28 04:51:33 Error: [ParseError] syntax error, unexpected ‘public’ (T_PUB LIC), expecting end of file in /var/www/clients/client4/web8/web/cms3021/src/Mod el/Table/ArticlesTable.php on line 12
Stack Trace:

  • /var/www/clients/client4/web8/web/cms3021/vendor/composer/ClassLoader.php:346
  • spl_autoload_call - [internal], line ??- class_exists - [internal], line ??- / var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Core/App.php :161
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Core/App. php:67
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/ORM/Locat or/TableLocator.php:291
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/ORM/Locat or/TableLocator.php:227
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Datasourc e/Locator/AbstractLocator.php:62
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/ORM/Locat or/TableLocator.php:205
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:172
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:389
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:210
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:122
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:98
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/bake/src/Command/Mode lCommand.php:81
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Console/B aseCommand.php:179
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Console/C ommandRunner.php:336
  • /var/www/clients/client4/web8/web/cms3021/vendor/cakephp/cakephp/src/Console/C ommandRunner.php:172
  • /var/www/clients/client4/web8/web/cms3021/bin/cake.php:12

As I copy pasted most of the tutorial, here’s my ArticlesTable.php:
<?php
// in src/Model/Table/ArticlesTable.php
namespace App\Model\Table;
use Cake\Validation\Validator;
// Urm.
use Cake\ORM\Table;
// the Text class
use Cake\Utility\Text;
// the EventInterface class
use Cake\Event\EventInterface;

public function validationDefault(Validator $validator): Validator {
$validator
->notEmptyString(‘title’)
->minLength(‘title’, 10)
->maxLength(‘title’, 255)

    ->notEmptyString('body')
    ->minLength('body', 10);

return $validator;

}

public function beforeSave(EventInterface $event, $entity, $options) {
if ($entity->isNew() && !$entity->slug) {
$sluggedTitle = Text::slug($entity->title);
// trim slug to maximum length defined in schema
$entity->slug = substr($sluggedTitle, 0, 191);
}
}
?>

This editor just scraps all my beautiful code formatting. Could do with some improvements. :confused:

I am running it on Ubuntu 18.04, Apache2, php 7.2 (detected 7.2.24-0ubuntu0.18.04.7).
The default page shows green checkmarks through the board.

Looks like you have made the ArticlesTable file yourself, not baked it? It’s entirely missing the class ArticlesTable { line, for example.

Ugh. :confused:
Thank you, I fixed it.

The tutorial seems to let me do it manually in the beginning, so I understand what’s going on.