Saturday, January 26, 2008

Magic of hook in CI

First change config.php in cofig directory

Search for $config['enable_hooks'] = false; make it ‘true’;

Add following in config/hook.php file


$hook['post_controller_constructor'] = array(

'class' => 'getSystem',

'function' => 'check',

'filename' => 'getsystem.php',

'filepath' => 'hooks'


);



For better configuration, try getting help from user_guide.

Create getsystem.php file in application/hooks directory

And paste the following:


<?php

//change the table name

if (!defined('BASEPATH')) exit('No direct script access allowed');

class getSystem

{

function check()

{

$CI =& get_instance();

$CI->db->query(”SELECT * FROM table_name”);

define('MAIL',true);

}

}

?>

try this controller

<?php

class Welcome extends Controller {

function Welcome()

{

parent::Controller();

}

function index()

{

echo MAIL;

$this->load->view('welcome_message');

}

}

?>