CakePHP3(3.0.0-beta1)でとりあえずHelperを作ってみる
CakePHP3(3.0.0-beta1)でとりあえずHelperを作ってみる
①ColorHelper.phpを作成
<?php namespace App\View\Helper; use Cake\View\Helper; class ColorHelper extends Helper { public function red($string) { return '<span style="color:red">' . $string . '</span>'; } }
②ArticlesControllerを下記のように変更
public $helpers = ['Paginator' => ['templates' => 'paginator-templates.php'],'Color'];
③index.ctpを下記のように変更
<th><?= $this->Color->red('Id') ?></th> <th><?= $this->Color->red('Title') ?></th> <th><?= $this->Color->red('Created') ?></th> <th><?= $this->Color->red('Action') ?></th>