Few lame questions

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

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

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

#4
[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

#5
[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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.