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');
}
}
}
}
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!