钩子笨版本3

问题描述:

我使用笨3。我已经使我的钩子钩文件钩子笨版本3

$hook['pre_controller'] = array(
     'class' => 'myclass', 
     'function' => 'myfunction', 
     'filename' => 'myfile.php', 
     'filepath' => 'hooks', 
     'params' => '' 
); 

扶持钩我得到了错误的

`Unable to locate the specified class: Session.php` 

请帮助来解决以上错误。我在配置文件中启用了驱动程序和库。

这是我在钩子使用

class Check_login extends CI_Controller 
{ 
    public function CheckLoggin() 
    { 
     $url = $this->uri->segment(1); 
     if($url == "givenparameter") 
     { 
      $login_id = $this->session->userdata("ID"); 
      $get_url = $this->uri->segment(2); 
      if($login_id == "" && $get_url != 'login') 
      { 
       redirect('controller/login', 'refresh'); 
      } 
     } 
    } 
} 

钩对会话类的依赖的代码。因此,尝试改变pre_controller挂钩post_controller'一样,

$hook['post_controller'] = array(
     'class' => 'Myclass', 
     'function' => 'Myfunction', 
     'filename' => 'Myfile.php', 
     'filepath' => 'hooks', 
     'params' => '' 
); 

如果没有作品,然后尝试,而不是post_controller

+0

雅我试着用这些东西,但得到了同样的错误。 – pabha

+0

@pabha尝试我更新的答案。 –

+0

雅感谢,尝试,但还是同样的错误 – pabha

钩子文件路径post_controller_constructor:应用程序/挂钩

控制器文件名:Blocker.php

class Blocker { 

    function Blocker(){ 
    } 
    function requestBlocker(){ 
      echo "done"; 
    } 
} 

此外,您还需要配置此。

配置路径:应用程序/配置/ hooks.php

$hook['pre_controller'] = array(
     'class' => 'Blocker', 
     'function' => 'requestBlocker', 
     'filename' => 'Blocker.php', 
     'filepath' => 'hooks', 
     'params' => "" 
); 

你也需要让你的配置挂钩。即。的application/config/config.php文件

+1

我想你第二个拦截功能的意义被__construct()https://www.codeigniter.com/user_guide/general/controllers.html#class-constructors – user4419336

+0

雅我曾尝试与以上的东西。如果我使用{扩展CI_Controller}我收到错误“无法找到指定的类:Session.php”。我们可以写使用CI_Model – pabha

+0

你有没有在配置文件$配置[“encryption_key”] =“yourkey”配置encryption_key; – Nobita