Help us understand the problem. What is going on with this article?

【CakePHP】HtmlHelper

More than 3 years have passed since last update.

参考: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

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

kazu56
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした