LoginSignup
1
0

More than 3 years have passed since last update.

【CakePHP3.8】CakePHP3で自作コンポーネントを作成、利用

Last updated at Posted at 2020-02-11

コード

コンポーネントの作成

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(処理を加える文字列など);
}

最後に

実行せず思い出しながらなので、
間違ってるかもしれません・・・
備忘録としてメモ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0