LoginSignup
0
0

More than 3 years have passed since last update.

【cakephp】FormHelperのlinkメソッド

Last updated at Posted at 2020-02-19

linkメソッド

HtmlHelperのlinkメソッドは、アクションを実行したときに指定したURLへ移動するための機能

  • 書き方
$this->Html->link('タイトル', $URL, $オプション);
$this->Html->link('タイトル', ['controller' => 'コントローラ名', 'action' => 'アクション名', 引数1, $クエリ文字列オプション]);
  • 具体例
$this->Html->link( $this->Html->image('画像', array("alt" => '代替テキスト', 'width'=>'n', 'height'=>'n')), 'javascript:window.close()', array('escape'=>false));

これを実行すると画像が表示、クリックすると第二引数のjavascript:window.close()が実行されwindowを閉じることができる

javascript:という書き方ですが自分も初めて知ったので今度記事にします
簡単に説明するとjavascriptをリンクのように扱える書き方です

第三引数の'escape'=>falseはhtmlの特殊文字を変換しないようにしてます

以下のhtmlが作成されます

<a href="javascript:window.close()">
 <img src="画像" alt="代替テキスト" width="n" height="n">
</a>

参考にしたサイト
【CakePHP入門】linkメソッドの使い方(HtmlHelper)
cookbook

0
0
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
0
0