我正在使用CodeIgniter控制器功能。 (例如)如何使用角度js重定向到CodeIgniter控制器
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Me extends CI_Controller {
public function __construct()
{
parent::__construct();
if (is_logged_in()){if (is_admin()) { redirect('login'); }}
else { redirect('login');}
}
public function change_password()
{
$id=$this->session->userdata['user_data']['id'];
$data = json_decode(file_get_contents("php://input"));
$my_data=array(
'pass'=>$data->pass,
'new_pass'=>$data->new_pass,
);
$result=$this->vanesh_model->change_pass($id,$my_data);
if($result==1)
{
$arr = array('msg' => "Password changed successfuly.", 'error' => '');
$jsn = json_encode($arr);
print_r($jsn);
}
else if($result==2)
{
$arr = array('msg' => "", 'error' => 'Old Password is Invalid');
$jsn = json_encode($arr);
print_r($jsn);
}
else if($result==3)
{
$arr = array('msg' => "", 'error' => 'Sorry, Password change failed');
$jsn = json_encode($arr);
print_r($jsn);
}
}
}
?>
恐怕採用了棱角分明的會話服務的,所以我要保持會話只CI。我在我的應用程序中所做的只是在登錄時添加,更新和刪除。而且我正在使用存儲在會話中的信息。考慮一下情況,假設我已經登錄並做了一些事情,並肩作戰:我使用瀏覽器工具銷燬會話。現在我繼續進行應用程序(執行如下操作:更改密碼)。我有/保留了錯誤信息,成功信息,確定。如果會話關閉,它會給出錯誤信息。但不是錯誤消息,我想重定向到LOGIN頁面(使用頁面刷新)。 注意:對於CI登錄控制器,我沒有使用角度js。我只有登錄後才使用angularjs。
- 如果通過打開新選項卡我銷燬會話,並回到應用程序的選項卡:我能夠執行任務(可能與錯誤,)。如果會話關閉,我在瀏覽器的控制檯中看到:
http://localhost/ums/login
這是因爲CI構造函數(請查看代碼)。