2013-10-17 83 views
0

我想要做一個單頁的應用程序,我有兩種類型的用戶。內容(儀表板)應根據登錄用戶的類型呈現。
現在,我對laravel和sammy.js都是全新的,我真的不知道如何處理它。處理內容afler登錄

我認爲工作流程應該如下:

  1. 爲每個用戶類型
  2. 用戶輸入的登錄憑據的儀表盤創建一個模板,點擊該按鈕
  3. Ajax調用PHP的那驗證憑證並返回用戶是否正確輸入了它們以及用戶的類型。
  4. Ajax獲取響應並用參數user_type調用一個新函數。根據用戶類型,正確的內容將被渲染。

現在,我的代碼如下所示:
//app/views/start.php

<form class="navbar-form pull-right" method="post" action="#/login"> 
     <input class="span2" type="text" placeholder="Email"> 
     <input class="span2" type="password" placeholder="Password"> 
     <button type="submit" class="btn">Sign in</button> 
</form> 

//public/js/myjs.js(呈現新的內容)

mtp = (function() { 
    var app = null; 
    var init = function($) { 

    app = $.sammy('#pagecontainer',function() { 
     this.use('Template'); 

    this.get('#/', function(){}); 
    this.post('#/submitrequestfrontpage', function(){ 
     context=this; 
     $("#pagecontainer").html(''); 
     context.render('addlifecircledata.template').appendTo($("#pagecontainer")); 
     }); 
    this.post('#/login',function(){ 
      //need to put intelligent stuff here 
      }); 
    }); 

$(function() { 
    app.run('#/'); 
}); 

}; 

return { 
    init: init 
} 
})(); 

雖然邏輯似乎沒問題,但我不知道該如何開始編寫代碼。具體來說,如何獲取myjs.js中的參數以啓動AJAX調用,然後獲取響應。

回答

0

您可以將它們存儲在HTML元素,比如

<input type="hidden" id="user_id" value="{{ $user_id }}" /> 

,稍後將與您myjs.js

,或者你可以指定在頭的所有變量$('#user_id').val()選擇,例如:

<head> 
    <script> 
     var user_id = '{{ $user_id }}'; 
    </script> 
    <script src="myjs.js"></script> 
</head>