Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取用户数据_Php_Codeigniter - Fatal编程技术网

Php 获取用户数据

Php 获取用户数据,php,codeigniter,Php,Codeigniter,我一直在构建的这个应用程序有两个部分。有一个由CMS提供动力的网站,还有一个与之配套的CMS(摔跤经理)。对于我创建的两个名为前端和后端的控制器,我会相应地使用它们。前端控制器负责需要在网站上的所有控制器上运行的代码。后端控制器负责需要在CMS上的所有控制器上运行的代码 我正在寻找一种理想的方法来处理用户数据,在用户再次成功登录后,它会被引导到由后端控制器扩展的仪表板。我听过不同的解决方案,比如钩子。这只是我听到的一个。你的朋友在这里吗 您只需创建一个主控制器(前控制器),它扩展了CI_控制器

我一直在构建的这个应用程序有两个部分。有一个由CMS提供动力的网站,还有一个与之配套的CMS(摔跤经理)。对于我创建的两个名为前端和后端的控制器,我会相应地使用它们。前端控制器负责需要在网站上的所有控制器上运行的代码。后端控制器负责需要在CMS上的所有控制器上运行的代码

我正在寻找一种理想的方法来处理用户数据,在用户再次成功登录后,它会被引导到由后端控制器扩展的仪表板。我听过不同的解决方案,比如钩子。这只是我听到的一个。你的朋友在这里吗

您只需创建一个主控制器(前控制器),它扩展了CI_控制器

你可以考虑做一个应用程序,如果有很多伟大的框架来帮助你实现这一点,很流行的一个是

class MY_Controller extends CI_Controller
{

    protected $currentUser;

    protected $template;

    public function __construct()
    {
        //You talked about hooks
        //this constructor is the same as saying
        //post_controller_constructor

        $this->template = 'master/default';
    }

    //Ok so what functions need to be run
    //throughout the application
    //run them once here, keeping our app DRY

    protected function isAjax()
    {
        return ($this->input->is_ajax_request()) 
               ? true 
               : show_error('Invalid Request!');
    }

    protected function isLoggedIN()
    {
       //load your auth library maybe here
       $this->load->library('auth');

       //check you have a "current logged In user"
       //expect object or null/false
       $this->currentUser = $this->auth->getLoggedInUser();

       return ($this->currentUser) ?: false;
    }
}

class Frontend_Controller extends MY_Controller
{
    public function __construct()
    {
       parent::__construct();
    }

    public function testFirst()
    {
         //maybe you just need to test for ajax request here
         //inheritance from parent
         $this->isAjax();
    }

    public function testSecond()
    {
        //maybe you DO need a user logged in here
         //inheritance from parent
         $this->isAjax();

         //or yet again, abstract this to the parent level
         if(!$this->currentUser || is_null($this->currentUser))
         {
             //handle errors on frontend
             return $this->output->set_status_header(401); //un-authorized
         }
    }
}