Rodhos Soft

備忘録を兼ねた技術的なメモです。Rofhos SoftではiOSアプリ開発を中心としてAndroid, Webサービス等の開発を承っております。まずはご相談下さい。

HTMLヘルパー

qiita.com

単純にリンク

<?= $this->Html->link("hello","http://rodhos.info/") ?>

は次のように変換される。

<a href="http://rodhos.info/">hello</a>

つまり、第1引数が表示する文字で、第2引数がURL。
第2引数は以下のように連想配列で指定することもできる。

<?= $this->Html->link(__('View'), ['action' => 'view', $article->id]) ?>
<a href="/kagero3/articles/view/1">View</a>

もう一つ例として

<?= $this->Html->link("hello",[ "controller" => "Articles", 
                                "action" => "home",
                                "1"]) ?>

は次のように変換される。

<a href="/kagero3/articles/home/1">hello</a>

第3引数

第3引数を指定するとaタグに属性をつけられる。

<?= $this->Html->link(  "hello",
                        "http://rodhos.info/",
                        ["class" => "button"]) ?>

は次のようになる。

<a href="http://rodhos.info/" class="button">hello</a>