0

我在項目中使用CakePHP 2.3.6 & Bootstarp。在菜單欄中,有一個我想要點擊的菜單,如果用戶登錄,發送Ajax請求並返回成功的消息,否則加載模式插件中的登錄頁面並讓用戶登錄。登錄頁面可以在同一頁面上,不需要使用模態插件來調用遠程頁面。當用戶在CakePHP 2.x中登錄時使用Bootstrap的Modal插件

這裏是僞代碼:

If(the user is logged in) 
    send an Ajax request to a page and show return message 
else 
    show the login page in the modal window 

我使用引導的模式插件在另一頁:

<?php echo $this->Html->link($user['User']['name'],array('controller'=>'users','action'=>'view',$user['User']['id']),array('data-toggle'=>'modal','data-target'=>'.modal'));?> 
. 
. 
. 
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"></div> 
    </div> 
</div> 
. 
. 
. 
<script> 
    $('.modal').on('hide.bs.modal',function(){ 
     $(this).removeData('bs.modal'); 
    }); 
</script> 

那麼,有沒有辦法做到這一點?

請幫幫我。

感謝

回答

0

,當點擊菜單按鈕,一個PHP頁面,PHP頁面中,如果用戶登錄後,您可以測試,如果是則可以發送一個Ajax請求:

<?php 
public function yourAjaxMethod() { 
    if ($this->UserModel->id) { 
     // do what you want to do end return the message to show 
     $message = 'Your message to show when return success data'; 
    }else{ 

     $message = false; 
    } 
    return $message; 
} 
?> 

而在你的成功,你的AJAX測試,如果該數據是虛假的或不

...,

success:function(data) { 
if (data == false) { 
    $('.modal').show(); 
}else{ 
    //append your message to any dom element 
    $(selector).append(data); 
} 

}

您的模態必須與菜單位於同一頁面,我不是sur,而是嘗試:)

+0

看起來像完美。好的,我會試試這個。 @ZakariaWahabi – 2014-10-27 04:25:20

相關問題