コード
コンポーネントの作成
App/Controller/component/HogeComponent.php
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
class HogeComponent extends Component{
function init() {
return $this;
}
public function hoge($itemName){
//処理内容
}
}
呼び出したいcontrollerで以下のようにする
class YobidashitaiController extends AppController
{
public $components = [
"Hoge" => [],
];
public $hoge;
}
実際に使うactionで以下のようにする
public function jissainiTukauAction()
{
$hoge = $this->hoge->init();
$hoge->hoge(処理を加える文字列など);
}
最後に
実行せず思い出しながらなので、
間違ってるかもしれません・・・
備忘録としてメモ。