LoginSignup
5
6

More than 5 years have passed since last update.

【CakePHP】HtmlHelper

Last updated at Posted at 2014-07-10

参考:Cookbook HtmlHelper

aタグを出力する→link

フォーマット
$this->Html->link('Enter', '/pages/home', ['class' => 'button', 'target' => '_blank']);
//=>出力結果
//<a href="/pages/home" class="button" target="_blank">Enter</a>

※第二引数のURLの指定
第二引数は、Html->url()へ渡されてurlになる。
よって、文字列で、'/pages/home'もしくは、配列で、['controller'=>'pages','action'=>'home']と書く。

※サニタイズを無効にする方法
第三引数に以下を設定する。

array('escape' => false)

scriptタグを出力する→script

フォーマット
$this->Html->script('scripts');
//=>出力結果
//<script type="text/javascript" href="/js/scripts.js"></script>

URLを直接指定することもできる。
jQueryのCDN使う場合は以下のような感じ。

$this->Html->script('http://code.jquery.com/jquery.min.js');
//=>出力結果
//<script type="text/javascript" href="http://code.jquery.com/jquery.min.js"></script>

urlを出力する→url

フォーマット
echo $this->Html->url(array(
    "controller" => "posts",
    "action" => "view",
    "hoge",
    "?" => ["foo" => "bar"],
));

// 出力結果
/posts/view/hoge?foo=bar

?をキーにすると、クエリストリングを作ることができる。

5
6
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
5
6