LoginSignup
3
5

More than 5 years have passed since last update.

CakePHP3 BootstrapUIで、col-md-xxを変更する

Last updated at Posted at 2017-12-15

やりたいこと

BootstrapUI の FormHelper::control() を使って表示される html の col-md-6col-md-8 変更したい。

こう書くと...

echo $this->Form->control('title', ['label' => 'タイトル']);

こういう出力になる。

<div class="form-group text">
<label class="control-label col-md-2" for="title">タイトル</label>
<div class="col-md-6">
<input type="text" name="title" id="title" class="form-control" value="">
</div>
</div>

デフォルトはこんな感じ
https://github.com/FriendsOfCake/bootstrap-ui/blob/master/src/View/Helper/FormHelper.php#L104-L111

やり方

全体に反映する場合

src/View/AppView.php
    use UIViewTrait;

    public function initialize()
    {
        $this->initializeUI();
        $helpers = $this->helpers();
        $helpers->Form->setConfig('grid.middle', 8);
    }

ビュー毎に反映させたい場合

src/Template/Controller/add.ctp
$this->Form->setConfig('grid.middle', 8);

まとめ

面倒だけど、ビュー毎に設定した方が無難 :sweat:

環境

  • CakePHP: 3.5.7
  • BootstrapUI: 1.2.1
3
5
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
3
5