* コントローラ [#ncb7eb90]

** アクションとテンプレートの構成例 [#da62d047]
showアクションを作成。URLは http://localhost/frontend_dev.php/goods/show になる。

- actions/actions.class.php
 <?php
 class goodsActions extends sfActions
 {
   public function executeShow()
   {
      $this->mesg = 'SHOW!';
   }
 }
- goods/templates/showSuccess.php
 <html>
 <body>
 <?php if ($mesg): ?>
 [<?php echo $mesg ?>]
 <?php endif; ?>
 </body>
 </html>

** アクションからテンプレートに値を渡す [#o5502374]
- アクション
 public function executeIndex()
 {
   $this->setVar('foo', 'bar');
   $this->foo = 'bar';
 }
- テンプレート
 <html><body>
 <?php echo $foo ?> <?php echo $bar ?>
 </body></html>

** アクションでテンプレートを指定する [#e7169d8b]
 public function executeIndex()
 {
   $this->setTemplate('foo');
 }
apps/frontend/modules/XXX/templates/fooSuccess.php が呼ばれる。

** リクエストオブジェクト [#q13a772c]
 public function executeIndex(sfWebRequest $request)
 {
    $name = $request->getPamareter('name', 'default_name');
 }

** リダイレクト[#q7b5ba1b]
 $this->redirect('/error/message'); 

** (メソッドの)転送 [#hf6c8836]
 $this->forward('top','index'); # topモジュールのindexメソッドへ転送

** セッション [#ue977ec0]
 $this->getUser()->setAttribute('mesg', 'エラーが発生しました'); # 設定
 $mesg = $this->getUser()->getAttribute('mesg');                 # 取得
 $mesg = $this->getUser()->hasAttribute('mesg');
 $this->getUser()->getAttributeHolder()->remove('mesg');         # 削除

 <html><?php $sf_user->getAttribute('mesg')?></html>             # テンプレートで参照する
http://symfony.xrea.jp/1.2/book/06-Inside-the-Controller-Layer.html#user.session
 
** フラッシュ [#c47f529d]
 $this->setFlash('mesg', 'エラーが発生しました'); # あるリクエストで設定する
 ↓ 
 $mesg = $this->getFlash('mesg');                 # 次のリクエストで取得する
 ↓                                               # さらに次のリクエストではもう消えていて取得出来ない


*** テンプレートでフラッシュを参照する [#h094a69b]
 <?php if($sf_flash->has('mesg')): ?>
  <?php $mesg = $sf_flash->get('mesg') ?>
 <?php endif ?>

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS