Best Method? |
[eluser]Cloak[/eluser]
Hi there. I'm new to CodeIgniter, and wondering of the best way to do the following. How would I go about including a view on the top and bottom of every page? Like a header and footer? I can't figure out if you can autoload views. Thanks.
[eluser]WebsiteDuck[/eluser]
I have a template.php view like this: Code: <?php and then in my controller when I show the view I do this: Code: $data['main_content'] = 'home';
[eluser]Sean Gates[/eluser]
There are several methods depending upon your needs. 1. Extend the controller class and within the __construct() and __destruct() add your header and footer views, respectively. (PHP5 only) Note: this locks you into those header and footer globally, which may be detrimental. 2. Add the header and footer to each controllers __construct() and __destruct(), respectively. (PHP5 only) 3. Add the header and footer to the function index() and create a passthru to all the other functions. (I can provide an example if you need). 4. Create a global view where you can pass the page data as a variable (as @WebsiteDuck mentioned) Hope that helps!
[eluser]tomcode[/eluser]
You can also work with a to all controllers common class, usually called MY_Controller. Wiki: How to extend the CI_Controller
[eluser]jedd[/eluser]
Hi Cloak and welcome to the CI forums. [quote author="Cloak" date="1263115475"] I'm new to CodeIgniter, and wondering of the best way to do the following. How would I go about including a view on the top and bottom of every page? Like a header and footer? [/quote] Be sure to familiarise yourself with the [url="/wiki/FAQ"]FAQ[/url], and indeed the rest of the [url="/wiki"]wiki[/url]. The FAQ contains the answer to this particular question, and likely the next few questions that you'll find yourself asking as you start to play with CI.
[eluser]Cloak[/eluser]
Hi everyone, thanks for the help! I've gotten it figured out. I used WebsiteDuck's method. |
Welcome Guest, Not a member yet? Register Sign In |