-1
我使用Tank Auth像幾個控制器:添加tank_auth驗證,多個控制器在笨
class Buscar_animal extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('tank_auth');
}
function index()
{
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->load->view('menu.php',$data);
$this->load->view('v_search',$data);
$this->load->view('footer');
}
}
//:...Several other functions
}
我想知道我如何申請條件:
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
}
我所有的控制器。
我想改變這一切就像控制器
class Buscar_animal extends MY_custom_controller {
}
和自定義應用邏輯是否。
有沒有一種有效的方法來做到這一點?
使控制器的所有將延長My_Controller(這必須位於核心文件夾吧?) – cMinor
對,沒錯。我認爲這是正確的,因爲有兩個原因:1)你避免了代碼重複(你只會定義一次這樣的事情)2)你堅持'Liskov替代原則' – Yang