php - Hooks and a MY_Model -
i hoping find answer question me. i'm jamie rumbelow's my_model , curious know if can use functionality if need run function inside of hook.
$hook['pre_controller'] = array( 'class' => 'logins_model', 'function' => 'pre_init', // run sort of function here 'filename' => 'logins_model.php', 'filepath' => 'models', //'params' => array('beer', 'wine', 'snacks') );
edit 2 : okay hook or have lost grasp of this?
<?php if (!defined('basepath')) exit('no direct script access allowed'); class user_hook { private $ci; function __construct() { $ci =& get_instance(); } public function validate_user() { $this->ci->load->model('logins_model', 'login'); //alternatively put in autoload.php $this->ci->load->model('users_model', 'user'); $user_id = $this->ci->session->userdata('user_id'); if (($user_id !== true) && (!is_numeric($user_id)) && (strlen($user_id) < 5)) { redirect('login'); } $user_data = $this->ci->user->get($user_id); $user_data->login = $this->ci->login->get_by('user_id', $user_id); if (empty($user_data)) { redirect('login'); } } }
yes, not using code suggest. need create own custom hook class , load (or autoload) , call model there.
it important note not work pre_controller
hooks codeigniter object not yet available. hook must post_controller_constructor
or later. take hook class example hooks/some_hook.php
.
class some_hook { private $ci; function __construct() { $ci =& get_instance(); } public function some_function() { $this->ci->load->model('logins_model'); //alternatively put in autoload.php $this->ci->logins_model->some_function_in_logins(); } }
then load using:
$hook['post_controller_constructor'] = array( 'class' => 'some_hook', 'function' => 'some_function', 'filename' => 'some_hook.php', 'filepath' => 'hooks' );
Comments
Post a Comment