Welcome Guest, Not a member yet? Register   Sign In
Few lame questions
#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.


Messages In This Thread
Few lame questions - by El Forum - 12-30-2007, 05:50 PM
Few lame questions - by El Forum - 12-30-2007, 06:56 PM
Few lame questions - by El Forum - 12-30-2007, 08:10 PM
Few lame questions - by El Forum - 12-31-2007, 05:21 AM
Few lame questions - by El Forum - 12-31-2007, 07:05 AM
Few lame questions - by El Forum - 12-31-2007, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB