2017-05-30 69 views
0

我使用笨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'); 
      } 
     } 
    } 
} 

回答

0

鉤對會話類的依賴的代碼。因此,嘗試改變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

0

鉤子文件路徑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