2011-12-18 4 views
0

「リフトを探検する」という本から若干修正したリスト4.7を使用して質問します。Liftのビューからスニペットにパラメータを渡すにはどうすればよいですか?

// In Boot.boot: 
LiftRules.viewDispatch.append { 
    case List("Expenses", "recent", acctId, authToken) => 
     Left(() => Full(RSSView.recent(acctId, authToken))) 

    // This is a dispatch via the same LiftView object. The path 
    // "/Site/news" will match this dispatch because of our dispatch 
    // method defined in RSSView. The path "/Site/stuff/news" will not 
    // match because the dispatch will be attempted on List("Site","stuff") 
    case List("Site") => Right(RSSView) 
} 

// Define the View object: 
object RSSView extends LiftView { 
    def dispatch = { 
     case "news" => siteNews 
    } 

    def recent(acctId : String, authToken : String)() : NodeSeq = { 
     // User auth, account retrieval here 
     ... 
     <lift:surround with="rss" at="content"> 
      <lift:Vote.image /> 
     </lift:surround> 
    } 

    // Display a general RSS feed for the entire site 
    def siteNews() : NodeSeq = { ... } 
} 

最近のビュー機能からのacctIdをsnippet lift:Vote.imageに渡すにはどうすればよいですか?ありがとう。

答えて

0

ユーザーのブート時にacctIdとauthToeknを取得しようとしている場合、これは機能しません。起動は、Webアプリケーションの起動時にのみ実行され、すべてのユーザーに対して一度ではありません。

ユーザーがログインするとき、または自動ログインCookieを検出したときにSessionVarを設定し、必要なところでsessionVarにアクセスする必要があります。

+0

私は起動からacctIdとauthTokenを取得するつもりはありません。私は別のコンテンツをレンダリングできるように、URLからacctIdを取得したい。しかし、SessionVarはこの目的に役立ちます。ありがとう。 – coolsuntraveler

関連する問題