Hi there. First I should say that I am fairly new to cakephp, so bear with me. I am trying to implement the dereuromark comments plugin in my test environment (cakephp 5.2, cakedc/users plugin and dereuromark cakephp-comments plugin) and I am facing a couple of issues which I need help/advice on to solve.
I have attached the comments plugin to an ‘Articles’ model in the project and the user is able to post a comment to an article item. However, on passing the comment data to the ‘add’ method of the Comments controller, the saving process is terminated at this line of code of the method:
$data[‘content’] = $data[‘comment’] ?? null;
The way I interpret this line of code is that if $data[‘content’] has a value (the comment tekst) it should be replaced by the $data[‘comment’] element in the further processing of the data. However, $data[‘comment’] is always empty in my case and I am not able to see where this element is taken from. My IDE also tells me that this element is undefined. If I modify the code to:
$data[‘content’] = $data[‘content’] ?? null;
the comment tekst is stored as expected. So I’m wandering if this is just a typo in the code, or I am missing something here.
The second issue I have is that the user_id of a commenting logged user is not stored in the table. The user_id should be passed to the $data[‘user_id’] element from the userId() method of the Comments controller. In my case it should be extracted from the user session. However, the userId() method is using ‘Auth.User’ as the session key:
return $this->getRequest()->getSession()->read(‘Auth.User.’ . $userIdField);
but in my case the session key is just ‘Auth’ without the user element. If I modify the code and replace ‘Auth.User.’ with ‘Auth.’ the user_id is passed to the $data[‘user_id’] element as expected and stored in the table. Am I missing something here or do I have to rename the user session key?
I should add that I am not accessing the Comments Component. If I have to do so to solve the issues, I would need some advice on how to use the component.
Any help/advice on this is appreciated.