CodeIgniter Forums

Full Version: Few lame questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Mantas M[/eluser]
Is it possible to have globaly loaded stuff in a hook class somehow? For example, to have a hook extended by hookController or smth?

Also, is it possible to use multiple Views? One to handle header, another for the content etc.

El Forum

[eluser]Craig A Rodway[/eluser]
For multiple views, I recommend Method 2 as described in the wiki.

El Forum

[eluser]Phil Sturgeon[/eluser]
Its not too easy setting default variables in a hook as hooks dont return data without setting a session var or something.

Try making a base class. This basically involves making a class called something like BaseController or Globals or something. Try one like this:

Code:
<?
class Globals extends Controller {

    var $data = array();
    
    // Chuck everything in here.
    function Globals()
    {            
        if(isValidUser()):
            $this->data['current_userID'] = getUserProperty('id');
            
            // Chuck in any "All Pages" Data here...
            
        
        endif;
        
    }

}
?>

Then in your other controllers, instead of extending Controller you extend Globals like so:

Code:
<?
include(APPPATH.'controllers/globals'.EXT);
class Normal_controller extends Globals {
    
    function index()
    {            
        $this->load->view('someview', $this->data);
    }

}
?>

Everything in the $this->data which is created in Globals will be available in any of its child controllers, and in any views that are passed the $this->data variable.

El Forum

[eluser]Mantas M[/eluser]
Thanks for the tips.

What I like in CI... That it's easy to hack hehe. It wouldnt be so easy to modify core of z I think Smile

El Forum

[eluser]Phil Sturgeon[/eluser]
Thats what I LOVE about CI. If you want rigid rules and lameness then go use Cake or Zend frameworks. CI lets you do what you damn well please! Big Grin

El Forum

[eluser]Josh Giese[/eluser]
Thanks for posting this. I'm 3 days into CI and I was wondering how to do something like this! I cant wait to go home and try it.