我在 My_Controller 中使用这个 remap 方法和 philsturgeon 的库
<?php
class MY_Controller extends MX_Controller
{
protected $data;
protected $view;
function __construct()
{
parent::__construct();
}
public function _remap($method, $parameters)
{
if($this->view === TRUE OR $this->view === '')
{
$this->template->build('default');
}else if(strlen($this->view) > 0){
$this->template->build($this->view);
}else{
$checkpoint = $this->session->flashdata('exit');
if($checkpoint){
exit();
}else{
$this->session->set_flashdata('exit',TRUE);
}
$this->redirect = base_url() . $this->redirect;
redirect($this->redirect);
}
}
}
在这里,我想在子控制器中知道如何处理这种情况
<?php
class Home extends My_Controller {
public $redirect = '/admin/dashboard';
public $view = FALSE;
function __construct()
{
parent::__construct();
}
function dashboard($days = '')
{
if (!$this->session->userdata('session_admin'))
{
$this->redirect = '/admin/login';
}else{
//display dashboard
}
}
function login()
{
if ($this->session->userdata('session_user')){
$this->redirect;
}else{
$this->view = 'login'; //Load login view through remap method with template library
}
}
}
如您所见,它进入一个循环并在 My_Controller 中以我的条件退出。虽然我已经创建了这个,但我想知道如何在这里处理重定向。什么应该是优化的解决方案。有什么建议么?