I am trying myself on cakephp, but it´s not working so far, and I don´t know why.
MODEL (group.php)
class Group extends AppModel {
var $name = 'Group';
}
Controller (GroupsController.php)
namespace App\Controller;
use App\Controller\AppController;
class GroupsController extends AppController{
var $name = 'Groups';
public function index(){
$this->set('groups', $this->Group->find('all'));
}
}
View (index.ctp)
<?php foreach ($groups as $group): ?>
<div class="groups">
<?= $this->element('groups', ['group' => $group]) ?>
</div>
<?php endforeach; ?>
I am getting ->
Error: Call to a member function find() on boolean
File C:\xampp\htdocs\cakephp\src\Controller\GroupsController.php
Line: 19
Can anybody point out the problem?
$this->Groupreference. The model is named incorrectly (should beGroupsTable(.php)), extends a (by default) non-existing class (AppModelis gone in 3.x, the base is now\Cake\ORM\Table), is missing the proper namespace declaration (App\Model\Table), and may even be placed in the wrong folder (just guessing on this one). And finally it should be$this->Groups(plural) in your controller.