我想在模特中制作自定义功能 -
我的控制器 -
<?php
namespace App\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\I18n\Time;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
class AdminsController extends AppController
{
public function planSessions()
{
$this->loadmodel('Plans_sessions');
$sessions = $this->Plans_sessions->getPlanSessions();
$this->set('sessions',$sessions);
}
}
我的模特 -
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class Plans_sessionsTable extends Table
{
public function getPlanSessions()
{
return $this->query("select * from `plans_sessions` where category LIKE '%shop%' ");
}
}
但它收到错误 - 未知方法“getPlanSessions”
答案 0 :(得分:0)
您应遵循命名约定:
http://book.cakephp.org/3.0/en/intro/conventions.html#model-and-database-conventions
表类名称是复数和CamelCased。 People,BigPeople和ReallyBigPeople都是传统模型名称的例子。
$this->PlansSessions->getPlanSessions();