Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter, how to make a template

im trying to ding into codeigniter MVC but i dont know how i make my template so i have 2 files (header and footer) and then i can make my controllers and then ONLY put information in the "content" div, so i include the top and the header a good way like this

<?php
include("header.php");
?>
<div id="content">My content here</div>

<?php
include("footer.php");
?>

hope you understand what i mean and can help me out :)

like image 668
Simon Avatar asked Apr 14 '26 05:04

Simon


1 Answers

The best way is to load views within your views.

Within views/content.php:

<? $this->view('header', array('title'=>'The page title', 'keywords'=>'some keywords', 'etc'=>'...')); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>

So in your controller you would do this:

$this->load->view('content', $data);

$data could contain 'title' or 'keywords' and that would be implemented as such in your controller:

$data['title'] = 'title';
$data['keywords' = 'keywords';

And this in your 'content' view:

<? $this->view('header', array('title'=>$title, 'keywords'=>$keywords)); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>

This question is worded differently, but nearly identical to this one in substance: CodeIgniter or PHP Equivalent of Rails Partials and Templates

like image 176
sholsinger Avatar answered Apr 17 '26 06:04

sholsinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!