LoginSignup
0
0

More than 5 years have passed since last update.

CakePHP3でのコンポーネントの使い方

Posted at

環境

CakePHP 3.5

コンポーネントとは

コントローラー間で共有されるロジックのこと。

参考:コンポーネント

コンポーネントの使い方

bakeコマンドでコンポーネントを作成

sh bin/cake bake component Hogehoge

コンポーネントに処理を書く

src/Controller/Component/HogehogeComponent.php
  public function hogehoge()
  {
    return 'hogehoge';
  }

コントローラーからコンポーネントを呼ぶ

src/Controller/HogehogeController.php

    /**
     * Initialize method
     *
     */
    public function initialize()
    {
        $this->loadComponent('Hogehoge');
    }

    /**
     * Index method
     *
     */
    public function index()
    {
        $this->Hogehoge->hogehoge();
    }
0
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
0
0