Codeigniter 2将控制器限制为命令行

时间:2022-10-06 23:02:25

I need to restrict a controller in CI 2 to only run from command line. The other controllers in the application are accessible from the web.

我需要将CI 2中的控制器限制为仅从命令行运行。可以从Web访问应用程序中的其他控制器。

What's the best way to do it?

最好的方法是什么?

1 个解决方案

#1


16  

You might want to check if is a CLI request:

您可能想要检查是否是CLI请求:

class Mycontroller extends CI_Controller {

   function __construct()
   {
     parent::__construct();

     if(!$this->input->is_cli_request())
     { 
       // echo 'Not allowed';
       // exit();
     }
   }

}

#1


16  

You might want to check if is a CLI request:

您可能想要检查是否是CLI请求:

class Mycontroller extends CI_Controller {

   function __construct()
   {
     parent::__construct();

     if(!$this->input->is_cli_request())
     { 
       // echo 'Not allowed';
       // exit();
     }
   }

}