Good evening, I’m currently finishing off an assignment, I’m trying to create a REST api on some methods and I’m getting a 500 Error. Please find attached 2 images.
The method is :
public function ApiComments($id) {
$commentsTable = TableRegistry::getTableLocator()->get(‘Comments’);
// Listing all comments
$allComments = $commentsTable->find()->contain(‘Users’)->where([‘item_id’=> $id]);
$selectedComments = $allComments->toArray();
$this->set([‘comments’=>$selectedComments,’_seralize’ => [‘comments’]]);
}
The template api_comments.ctp is not being found. Did you create it in the expected directory?
Also, there is something odd about that .ctp name. I don’t think the ‘\u0022’ should be showing up there. If you have created the template then figuring out whey that additions bit is on there should fix things.
given that \u0022 is a quote, and it appears at both ends of that .ctp path, it’s probably nothing more than an artifact of the way the error message appears in the json object.
It seems likely then that you’ve either not made the file, not made it in the right directory, or have a typo in the name.