[eluser]boltsabre[/eluser]
There's a few ways to go about it:
- You can extend the base controller with MY_Controller, thus any other "normal" controller that extends this will have access to your code.
- For your "sign in / sign up" links I just check for my session variable inside my view code and echo out the appropriate link (and username if they are logged in). I'm happy with this, but others will have their own opinion/view on this.
- You can use a template format for including "page modules" (header, footer, side nav, etc).
I actually have my modules divided up like this, and just include them in each view (I'm not using the template method).
Code:
// a view file
<?php $this->load->view('includes/header_open'); ?>
// header open has normal stuff like site wide stylesheet, js file, favicon, doctype, etc
// If this particular page needs anything specific, like a JS file, CSS stylesheet, etc, just code it in here
<?php $this->load->view('includes/header_close'); ?>
//Head close includes closing </head> tag, opening <body> tag, top icon image, top nav bar, login/signup stuff, etc
// body content goes here
<?php $this->load->view('includes/footer_open'); ?>
// footer open has my closing body wrapper div, and my "footer" with "contact us, copyright, etc
// If I need any JS at the bottom for this view put it here
<?php $this->load->view('includes/footer_close'); ?>
//this is the closing </html> tag, etc
Problem with this method is that I have to put these includes in each and every view file, and if I ever want to change the format I'm in for a hell of a lot work updating each view, but it gives me the flexibility to include specific JS files on individual pages manually, place inline JS up in the header, or footer, etc.