2015-09-26 34 views
1

我想自定義函數模型中 -如何在cakephp 3的模型中設置默認函數?

我的控制器 -

<?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

你應該遵循命名約定:

http://book.cakephp.org/3.0/en/intro/conventions.html#model-and-database-conventions 

表類名稱是複數和駝峯。 People,BigPeople和ReallyBigPeople都是傳統型號名稱的例子。

$this->PlansSessions->getPlanSessions();