Help us understand the problem. What is going on with this article?

CakePHP3で自作コンポーネントを作成、利用

コード

コンポーネントの作成

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

最後に

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

JJJJJJJJ
最近はRuby書いたりAWS触ったり。
it-geinin
技術を使って日々面白いことに挑戦し、Qiitaに投稿します。技術を楽しむ会です。
http://it-geinin.org/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした