CakePHP Behavior謫堺ス

繝薙倥う繝薙い縺ィ縺ッ

繝「繝繝ォ縺九i蛻ゥ逕ィ縺吶k蜈ア騾壼ヲ逅
迚ケ螳壹ョ繝「繝繝ォ縺ォ髯仙ョ壹@縺ェ縺蜃ヲ逅繧定ィ倩ソー縺励※縲∫音螳壹ョ繝「繝繝ォ縺九i蛻ゥ逕ィ縺吶k

繝薙倥う繝薙い縺ョ菴懈

Behavior

窶サsrc\Model\Behavior\UtilBehavior.php
namespace App\Model\Behavior;

use Cake\ORM\Behavior;
use Cake\ORM\Table;

class UtilBehavior extends Behavior {

public function initialize(array $config){
縲縲parent::initialize($config);
縲}

縲public function getAll() {
縲縲迚ケ螳壹ョ繝「繝繝ォ縺ァ縺ェ縺繝「繝繝ォ繧呈桃菴
縲縲return $this->_table->find()->all();
縲}
}

Model

class ス杁able extends Table
{
縲public function initialize(array $config){
縲縲parent::initialize($config);
縲縲ス
縲縲繝薙倥う繝薙い縺ョ繝ュ繝シ繝
縲縲$this->addBehavior('Util');
縲}
}
縲ス
}

繝薙倥う繝薙い縺ョ蛻ゥ逕ィ

Controller

namespace App\Controller;
class ス曚ontroller extends AppController
{
縲public function initialize(){
縲縲parent::initialize();
縲縲$this->ス= TableRegistry::get('ス');
縲}

縲public function index(){
縲縲$ret = $this->ス->getAll();
縲}
}

Follow me!

蜑阪ョ險倅コ

CakePHP Component謫堺ス

谺。縺ョ險倅コ

CakePHP Helper謫堺ス