LoginSignup
0

More than 5 years have passed since last update.

CakePHP3新機能 Cellメソッドの引数について

Last updated at Posted at 2016-12-20

Cellメソッド

引数は3つ。
最後のオプションについてはView\Cell::$_validCellOptionsによる特殊なコントロールが可能。

Template/xxx/index.ctp
<?= $this->cell(string $cell_name, array $data, array $options)->render() ?>

第一引数

呼び出したいCellの名前

<?= $this->cell('Hoge')->render() ?>

第二引数

Cellに渡したいデータ群。
HogeCell::displayの引数として配列への指定順に渡される。

Template
<?= $this->cell('Hoge', ['aaa', 'bbb', 'ccc'])->render() ?>
View\Cell
class HogeCell extends Cell
{
     public function display($aaa, $bbb, $ccc) {}
}

第三引数

Cellに渡したいオプション。
View\Cell::$_validCellOptions によって渡せるオプションを制御できる。

Template
<?= $this->cell('Hoge', [], ['xxx' => 1, 'yyy' => 2])->render() ?>

オプションは$thisからプロパティとして呼び出せる。

View\Cell
class HogeCell extends Cell
{
     protected $_validCellOptions = ['xxx'];

     public function display()
     {
         echo $this->xxx;
         echo $this->yyy;
     }
}

$_validCellOptions においてxxxのみが許可されているため、$this->yyyは呼び出せない。

result
1
Notice (8): Undefined property: App\View\Cell\HogeCell::$yyy[APP/View/Cell/HogeCell.php, line 28]

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