CodeIgniter Forums
Few lame questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Few lame questions (/thread-5006.html)



Few lame questions - El Forum - 12-30-2007

[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.


Few lame questions - El Forum - 12-30-2007

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


Few lame questions - El Forum - 12-30-2007

[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.


Few lame questions - El Forum - 12-31-2007

[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


Few lame questions - El Forum - 12-31-2007

[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


Few lame questions - El Forum - 12-31-2007

[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.