I’m a first-time PHP frame user, but have written some fundamental PHP apps so I know my way around it enough. I used Oven to bake this cake (from the installation link on the first page of the tutorial), as I don’t have admin on my TTY access to my webhost and composer is not installed - that may be relevant to some of these issues - in which case that should be mentioned in the tutorial.
Here’s are some issues and suggestions for the tutorial. This does not include the error spotted here: CMS tutorial beforeSave with tag_string
Firstly it would be good to actually have a home screen, instead of manually typing …/articles - after all I would consider that relevant to building a home page. Even if its an automatic redirection to the …/articles.php page - in which case what is the correct CakePHP way of doing that? (I am assuming it’s an edit of ./templates/Pages/home.php - but what should actually be put in there?)
It could otherwise be maintained during the tutorial, adding the links as relevant, like the final logout link, thus rounding the tutorial off within a package.
Bad link: -
On the /articles page there is a link in the top right titled “API” which refers to https://api.cakephp.org/4/ which gives [me] a 404 error.
Wrong instruction: -
“In src/Template/Articles/view.php add the line as shown:” should be “In Template/Articles/view.php add the line as shown:”. I know this is obvious to everyone else, but still learning the layout means its not obvious first time around.
Wrong code: -
$article = $this->Articles
->contain(‘Tags’) // load associated Tags
$article = $this->Articles
No tag. Again it may be obvious looking, but at this stage in the tutorial I didn’t know that “tag” was not a built-in Cake reserved-word, or object property (as a Delphi programmer that could be an assumption). The tags are added on the next page of the tutorial, but I had debugged this before moving on and thus realising then what it was!
The comment “// Hardcoding the user_id is temporary, and will be removed later when we build authentication out.”
But it isn’t. Even in the final version of src/Controller/ArticlesController.php that comment is still there. I would like to be able to attribute the person who wrote the article to the user logged in. I tried this: -
$article->user_id = $this->Auth->User(‘user_id’);
$article->user_id = $this->Auth->User(‘id’);
$article->user_id = $this->Auth->Users(‘user_id’);
$article->user_id = $this->Auth->Users(‘id’);
$article->user_id = $this->Authentication->User(‘id’);
and all variations of field names, case etc.
Also I tried this: -
$u = $this->Auth->user();
$uid = $u[‘User’][‘id’];
$article->user_id = $uid;
Am I missing a uses unit?
I read here https://stackoverflow.com/a/19169289/530047 there are other ways to get the user id, but as I am in a Controller here I want to use the command recommended for a controller.
Nevertheless, these also did not work: -
$article->user_id = $this->Session->read(‘Auth.User.id’);
$article->user_id = CakeSession::read(‘Auth.User.id’);
article->user_id = _SESSION[‘Auth’][‘User’][‘id’];
So I’m stumped on this one! (I still I may be missing a unit?)
I downloaded the source provided on github and it had: -
// Added: Set the user_id from the session.
$article->user_id = $this->Auth->user(‘id’);
Which, also, yielded as error (as expected as I had already tried this) of: -
Notice (1024): Undefined property: ArticlesController::$Auth in …/src/Controller/ArticlesController.php on line 41 [CORE/src/Controller/Controller.php, line 314]
Error: Call to a member function user() on null
Code is different on github: -
Either the tutorial is out of date, or github is. But github is different, with lines like: -
in src/Controller/ArticlesController.php initialize()
Note that adding that line caused my app to crash with “Call to a member function allow() on null”.
So as both our apps are broken I have run out of options!! At this point I have given up trying to debug either of them.
Allow me to say thanks for sharing this wonderful product. I hope with these minor adjustments and additions this tutorial will be easier to follow for others.