CodeIgniter Forums
[Solved] Hooks not working with HMVC - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [Solved] Hooks not working with HMVC (/showthread.php?tid=66106)



[Solved] Hooks not working with HMVC - wolfgang1983 - 09-05-2016

I have a controller called Login.php and is class is Login

And a function called check()

I would like the hook to check that function first how ever even with testing code it not working on HMVC

Not sure why not work with HMVC? Its not throwing any errors I have enabled hooks on config.php

Any ideas?


PHP Code:
$hook['pre_controller'] = array(
    'class'    => 'Login',
    'function' => 'check',
    'filename' => 'Login.php',
    'filepath' =>  'application/modules/admin/controllers/common/'
); 

Login

PHP Code:
<?php

class Login extends MX_Controller 
{
    private $error = array();

    public function __construct() 
    {
         parent::__construct();
         $this->load->library('form_validation');
         $this->load->model('admin/common/login_model');
    }

    public function index() {
        $this->form_validation->set_rules('username''username''trim|required');
        $this->form_validation->set_rules('password''password''trim|required|valid_password');

        if ($this->form_validation->run() == true) {

            redirect('admin/user/users');
        }

        if (validation_errors() != ''
        
             $this->error['warning'] = validation_errors('<div class="alert alert-danger">''</div>'); 
        }

        if (isset($this->error['warning'])) 
        {
            $data['warning_error'] = $this->error['warning'];
        
        else 
        
{
            $data['warning_error'] = '';
        }

        $data['header'] = Modules::run('admin/common/header/index');
        $data['footer'] = Modules::run('admin/common/footer/index');

        $this->load->view('common/login_view'$data);
    }

    public function check() 
    {
        echo "Hello";

        $segment $this->uri->segment(1) .'/'$this->uri->segment(2) .'/'$this->uri->segment(3);

        if ($this->uri->segment(1) == 'admin') {

            $ignore = array(
                'admin/common/login',
            );

            if (!$this->login_model->is_logged() && !in_array($segment$ignore)) {
                redirect('admin/common/login');
            }

        }
    }





RE: Hooks not working with HMVC - wolfgang1983 - 09-05-2016

Found my error did not need to have application


PHP Code:
$hook['pre_controller'] = array(
    'class'    => 'Login',
    'function' => 'check',
    'filename' => 'Login.php',
    'filepath' => 'application/modules/admin/controllers/common/'
); 


To


PHP Code:
$hook['pre_controller'] = array(
    'class'    => 'Login',
    'function' => 'check',
    'filename' => 'Login.php',
    'filepath' => 'modules/admin/controllers/common/'
);