如何在 Codeigniter 中仅禁用特定方法的构造函数?
How do I disable a constructor for only a particular method in Codeigniter?
我在这个用户中有超过 30 个方法Controller.I不想只为这个方法创建另一个控制器。
class User extends CI_Controller {
public function __construct()
{
parent::__construct();
if(empty($_SESSION['userid'])){
$error['error'][] = "Please LogIn";
echo json_encode($error);
exit;
}
}
public function index(){
}
public function get_public_pages(){
}
}
访问get_public_pages时不想让构造函数运行method.How可以吗?
试试这个,
public function __construct(){
parent::__construct();
$method = $this->router->fetch_method();
if(empty($method ) && $method != 'get_public_pages'){
if(empty($_SESSION['userid'])){
$error['error'][] = "Please LogIn";
echo json_encode($error);
exit;
}
}
}
我在这个用户中有超过 30 个方法Controller.I不想只为这个方法创建另一个控制器。
class User extends CI_Controller {
public function __construct()
{
parent::__construct();
if(empty($_SESSION['userid'])){
$error['error'][] = "Please LogIn";
echo json_encode($error);
exit;
}
}
public function index(){
}
public function get_public_pages(){
}
}
访问get_public_pages时不想让构造函数运行method.How可以吗?
试试这个,
public function __construct(){
parent::__construct();
$method = $this->router->fetch_method();
if(empty($method ) && $method != 'get_public_pages'){
if(empty($_SESSION['userid'])){
$error['error'][] = "Please LogIn";
echo json_encode($error);
exit;
}
}
}