Welcome Guest, Not a member yet? Register   Sign In
Header and Footer (Help needed)
#1

[eluser]navetz[/eluser]
I have just started using code igniter and I love it.

I want to know hot to use set a header and footer without having to load it in your controller or view everytime.

Can you set up hooks to do this? If you do can you add variables to the controller to modify the hooks?

Example:

Set up a hook to load your header then do this:

Code:
$data['homeTitle'] = 'page Title';
$this->load->view('Template_page', $data);

However homeTitle is in your header hook and not your view Template_page.

I am new to codeigniter and have never developed anything with it before. Tomorrow will be my first day so please tell me if I am way off in my way of thinking lol.
#2

[eluser]kyleect[/eluser]
This is an extremely common question and there are a lot of threads on the boards about it. In my opinion, the best place to start is with MY_Controller. Here is mine and should provide a decent stepping stone in developing yours.

(I had to post a link because the board filters some of the code for some reason saying [removed]
http://pastebin.com/m13a8d7ea
#3

[eluser]jedd[/eluser]
[quote author="navetz" date="1253453011"]
I have just started using code igniter and I love it.
[/quote]

Hi navetz and welcome to the CI forums.

Quote:I want to know hot to use set a header and footer without having to load it in your controller or view everytime.

We have a wiki, too, that you can use.

[url="http://codeigniter.com/wiki/"]wiki[/url] | Approaches | Header and Footer ... on every page
#4

[eluser]benoa[/eluser]
Hi navetz, have a look at <a href="http://net.tutsplus.com/videos/screencasts/5-super-helpful-web-development-video-quick-tips/">this five-minute screencast from Nettuts</a>. It's a nice trick I'm using on the backend of my site.
#5

[eluser]BrianDHall[/eluser]
In short, I recommend you use a MY_controller (extending the base controller class), or more simply just use your constructor in your controller to load your "partial views" into variables, then in your template (the last view you call to send the full webpage to the user) print out the variables in the appropriate place.
#6

[eluser]navetz[/eluser]
I watched the video tutorial and I took a look at MY_controller.

I am not sure which one is the better solution yet, but I think I will try the MY_controller solution first.

Hopefully I don't come across any restrictions.
#7

[eluser]benoa[/eluser]
It actually depends wether if you prefer a "bottom up" or "top down" approach. I can see a lot of debates in programming-related forums, and in the end, everyone argues for the way his mind is built. Sorry for the off topic!
#8

[eluser]navetz[/eluser]
I just think extending the controller will be easier then including the header and footer in every view.
#9

[eluser]navetz[/eluser]
How can I tell code igniter I am using php 5? It is giving me errors for __construct().

I was forced to create a constructor method:

class MY_Controller extends Controller
{
__construct()
{
//some stuff
}

MY_Controller()
{
$this->__construct()
}
}

Anyone know whats up with that?
#10

[eluser]kyleect[/eluser]
It should be

Code:
public function __construct()
{
    parent::__construct();
}




Theme © iAndrew 2016 - Forum software by © MyBB