2006-04-05
■[symfony] helper の使い方

View上でリンクやフォームを使うには、helper を利用して記述する。
あまり慣れていないので、最初は戸惑ったが慣れると便利です。
Link Helper
- 普通のリンク
<?php echo link_to('Link String', 'moduleName/functionName?parameter=value') ?>
↓
<a href="/moduleName/functionName/parameter/value" title="interesting article">Link String</a>
- 画像リンク
<?php echo link_to(image_tag('imageName'), 'moduleName/functionName') ?>
↓
<a href="/moduleName/functionName"><img src="/images/imageName" alt="imageName" /></a>
- フォーム送信したい場合
<?php echo link_to('Link String', 'moduleName/functionName', 'post=true') ?>
↓
<a onclick="f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();return false;" href="/moduleName/functionName">Link String</a>
- その他
<?php echo link_to('Link String', 'moduleName/functionName', 'confirm=遷移します、よろしいですか?') ?>
↓
<a onclick="return confirm('遷移しますよろしいですか?');" href="/moduleName/functionName">Link String</a>
<?php echo link_to('Link String', 'moduleName/functionName', 'popup=true') ?>
↓
<a onclick="window.open(this.href);return false;" href="/moduleName/functionName">Link String</a>
<?php echo link_to('Link String', '/moduleName/functionName', Array('popup' => Array('Window title','width=310,height=400,left=320,top=0'))) ?>
↓
<a onclick="window.open(this.href,'Window title','width=310,height=400,left=320,top=0');return false;" href="/moduleName/functionName">Link String</a>
<?php echo link_to('Link String', '/moduleName/functionName', 'confirm=送信します、よろしいですか? post=true') ?>
↓
<a onclick="if (confirm('送信します、よろしいですか?')) { f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;" href="/moduleName/functionName">Link String</a>
<?php echo link_to('Link String', '/moduleName/functionName', 'confirm=別ウィンドウを開きます、よろしいですか? popup=true') ?>
↓
<a onclick="if (confirm('別ウィンドウを開きます、よろしいですか?')) { window.open(this.href); };return false;" href="/moduleName/functionName">Link String</a>
Button Helper
- 普通のボタン
<?php echo button_to('Button Value', '/moduleName/functionName') ?>
↓
<input value="Button Value" type="button" onclick="document.location.href='/moduleName/functionName';" />
- サブミットボタン
<?php echo button_to('Button Value', '/moduleName/functionName', 'post=true') ?>
↓
<form method="post" class="button_to" action="/moduleName/functionName"><input value="Button Value" type="submit" /></form>
- その他
<?php echo button_to('Button Valu', '/moduleName/functionName', 'confirm=別ウィンドウを開きます、よろしいですか? popup=true') ?>
↓
<input value="Button Valu" type="button" onclick="if (confirm('別ウィンドウを開きます、よろしいですか?')) {window.open('/moduleName/functionName');}" />
Mail Helper
- 普通
<?php echo mail_to('mail Address', 'Link String') ?>
↓
<a href="mailto:mail Address'>Link String</a>
<?php echo mail_to('mail Address', 'Link String', array('encode' => true)) ?>
↓
<a href="mailto:my">con</a>
Image Helper
Javascript Helper
コメントを書く
トラックバック - http://d.hatena.ne.jp/hir_kaz/20060405/1144287376
リンク元
- 6 http://www.technorati.com/search/symfony?language=ja
- 6 http://www.technorati.jp/tag/symfony
- 3 http://maple.ring.hatena.ne.jp/
- 3 http://www.symfony-project.com/weblog.html
- 2 http://d.hatena.ne.jp/keyword/YAML
- 2 http://maple.ring.hatena.ne.jp/rss/
- 2 http://technorati.com/search/symfony
- 1 http://72.14.203.104/search?q=cache:V0s1MmEP89IJ:www.technorati.jp/tag/symfony+symfony+インストール&hl=ja&gl=jp&ct=clnk&cd=7
- 1 http://b.hatena.ne.jp/t/symfony
- 1 http://d.hatena.ne.jp/keyworddiary/momoko
