Welcome Guest, Not a member yet? Register   Sign In
header and footer
#1

[eluser]tj[/eluser]
am new to ci frame work and to php .is there any way to add the header and footer to all views without repeting $this->load->view('header'); in all my controller.
something like autoload hreader and footer.

tnx in advance
#2

[eluser]briskdeveloper[/eluser]
Hi,

Even am looking for same thing If u find the solution for this plz let me know.

Thanks,
shakeeb
#3

[eluser]N'hono[/eluser]
Hi !
For the header, there's a simple way to do it. You can create a "super" controller that heritated from Controller and that your others controller will be heritated. In the constructor of this "super" controller, you load the view "header".

For example,

Code:
// file application/controller/SuperController.php
class SuperController extends Controller {
   function SuperController() {
      parent::Controller();
      $this->load->view('header');
   }
}

// file application/controller/AController.php
class AController extends SuperController {
   function AController() {
      parent::SuperController();
      //...
   }
   //...
}

But I tried the same for the footer in the desctructor method and it didn't work...Anybody has an idea ?
#4

[eluser]briskdeveloper[/eluser]
hey did u tried the template system in codeigniter to solve this problem?

shakeeb.
#5

[eluser]tatewaky[/eluser]
[quote author="tj" date="1258132342"]am new to ci frame work and to php .is there any way to add the header and footer to all views without repeting $this->load->view('header'); in all my controller.
something like autoload hreader and footer.

tnx in advance[/quote]

Hey i was wondering the same thing 3 days ago, and i found a great solution that works just great for me, i hope for you too.

First: your controller index method:
Code:
$data['main_content'] = 'your_view';
$this->load->view('template', $data);

And finally your template view:

Code:
<?php $this->load->view('header'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('footer'); ?>

i found this information on this video tutorial that also will help you with a login process
#6

[eluser]jedd[/eluser]
[quote author="tj" date="1258132342"]
am new to ci frame work and to php
[/quote]

Evidently.

You may be fascinated to learn that we have a [url="/wiki/"]wiki[/url].

It has interesting articles in it, like [url="/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]this one[/url].
#7

[eluser]N'hono[/eluser]
[quote author="tatewaky" date="1258146400"][quote author="tj" date="1258132342"]am new to ci frame work and to php .is there any way to add the header and footer to all views without repeting $this->load->view('header'); in all my controller.
something like autoload hreader and footer.

tnx in advance[/quote]

Hey i was wondering the same thing 3 days ago, and i found a great solution that works just great for me, i hope for you too.

First: your controller index method:
Code:
$data['main_content'] = 'your_view';
$this->load->view('template', $data);

And finally your template view:

Code:
<?php $this->load->view('header'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('footer'); ?>

i found this information on this video tutorial that also will help you with a login process[/quote]
thanks a lot ! It was the one i didn't see yet ! I'm going to do it !
#8

[eluser]Aken[/eluser]
I used a small Library I wrote to show a page with a header/footer. So my view file for that page is loaded in a way such as:
Code:
$this->template->view('view_name', $data);

I also have some other features relating to a small amount of dynamic information in the header/footer, but that's not important. I found that doing things this way was less confusing as extending the core Controller class, and also allowed me to be more dynamic with my templates. For example, I have different header/footers for different parts of my website.
#9

[eluser]tj[/eluser]
thank u guys i just love this forum u guys are awesome
#10

[eluser]jedd[/eluser]
[quote author="tj" date="1258132342"]
is there any way to add the header and footer to all views
[/quote]


[quote author="tj" date="1258624503"]
i just love this forum
[/quote]

I hope you've also learned to love the [url="/wiki"]wiki[/url], especially the [url="/wiki/FAQ"]FAQ[/url], even more.




Theme © iAndrew 2016 - Forum software by © MyBB