My Demo Controller (DemoController.php):
<?php
namespace App\Controller;
class DemoController extends AppController
{
public function users()
{
$this->loadmodel('registration');
$result = $this->registration->getAllUsers();
$this->set('user_data',$result)
}
}
?>
My registration model (registration.php):
<?php
namespace App\Model;
use Cake\ORM\TableRegistry;
class Registration extends AppModel {
$articles = TableRegistry::get('registration');
public function getAllUsers()
{
return $query = $articles->find();
}
}
?>
My View:
path -- src/Template/Demo/users.ctp
but it's getting error like this (in below image) --
Your model should be named RegistrationsTable
, and be in src/Model/Table/RegistrationsTable.php
. Load it with loadModel('Registrations')
. (It's your entity that should be named Registration
.) To use your custom finder method, name the function findAllUsers, fix the signature per the documentation (should take two parameters: Query $query, array $options
) and call it as $this->Registration->find('all_users');
.
And why are you trying to initialize a $articles
variable as the registrations model inside the registrations model (but outside of any function)? So much mess...