LoginSignup
1
3

More than 5 years have passed since last update.

CakePHP3:admin用のレイアウト

Last updated at Posted at 2016-12-22

レイアウトの作成

mkdir -p app/src/Template/Admin/Layout
cp app/src/Template/Layout/default.ctp app/src/Template/Admin/Layout/admin.ctp

AppControlllerを編集し、prefixに応じてlayoutを選択

src/Controller/AppController.php
    public function beforeRender(Event $event)
    {
        // 以下の5行を追加
        if ($this->request->param('prefix') === 'admin') {
          $this->viewBuilder()->layout('admin');
        } else {
          $this->viewBuilder()->layout('default');
        }
        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    }
1
3
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
3