[eluser]Crackz0r[/eluser]
Hello.
You could use a Template system like this:
IN your views folder you could create a subfolder called
includes, right there you could create 3 files: header.php, template.php, footer.php (although you could use as many as you need to use "fixed content"). And that files are:
template.php:
Code:
<?php
if (!defined('BASEPATH')) { exit('No direct script access allowed'); }
$this->load->view('includes/header'); //here you load the header view, in the includes folder, which is a fixed content in all your pages... i think
$this->load->view($main_content); //this variable is what i'm using to load a view dynamically
$this->load->view('includes/footer'); //here you load the header view, in the includes folder, which is a fixed footer content.
?>
header.php:
This is the html contento for the header...itt could looks like this, which is my case
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="<?php echo base_url(); ?>media/favicon.ico" />
<link rel="shortcut icon" href="<?php echo base_url(); ?>media/favicon.png" type="image/png" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/global.css" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/project/jquery-ui-1.8.20.custom.css" />
[removed][removed]
[removed][removed]
<title><?php echo $title ?></title>
</head>
<body>
<div class="header left" id="header" >
<a href="<?php echo base_url() ?>"><img src="<?php echo base_url() ?>media/logo.png" border="0" class="left" alt="VetBoard.CO" /></a>
</div>
<div>HERE YOU COULD I.E. SET YOU MENU NAV BAR</div>
As you can see, it's is a normal html page with all the featuresw it needs... Also, note that the title, is a vairable, which we will se how to set it up in some moments.
footer.php
Here you then need to close the body and html tags, as well as you can set any static content, which will be seen in all your pages as the header.
Code:
<div>ANY CONTENT YOU WANT TO BE SHARED IN ALL YOUR PAGES</div>
</body>
</html>
This is almost the full body structure of your site... now lets see the controler, its called, humm,
login and ofc its placed whitin you controllers folder in you application folder... as usual.
login.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library(array('form_validation'));
$this->load->helper(array('form', 'url', 'string'));
}
public function index()
{
if($this->session->userdata('logged_in') === TRUE)
{
redirect('/dashboard/', 'location');
}
else
{
$show['title'] = 'My Site Title, loaded in the view and changed dynamically in each of you controller';
$show['main_content'] = 'login_view';
$this->load->view('includes/template', $show);
}
}
Here as you can see... not the function itself, what i want to show you is, the
else part, when you call a view, there are a few variables, the
title and that called
main_content, the title, is the title that you may want to set in that specific part of your site, the other variable, is the fragment or the single view wich is going to be loaded in the template.php file, if your remember, there was a piece:
$this->load->view($main_content); well passing this as a variable, you are allowed to set in each controller a specific view to load... and then you load the view in the last line:
$this->load->view('includes/template', $show); passing the variables as parameters for the template view...
Now finally lets create the login view, which will be placed in your
views folder,
NOT IN the includes folder and here is:
login_view.php
Remember, file placed in views folder and called as you loaded it:
login_view
Code:
<?php echo form_open('account/signin'); ?>
<ul>
<li>
<label for="email">e-Mail: </label>
<input id="email" name="email" type="text" value="<?php echo set_value('email'); ?>" />
</li>
<li>
<label for="password">Password: </label>
<input id="password" name="password" type="password" />
</li>
<li>
<label></label>
<span>input type="submit" value="Log in" style="width:120px"/>
</span>
</li>
</ul>
<?php echo form_close(); ?>
And thats it, you will get a full html page, with dynamic content and easy to manage and maintain, since you will only need to create, modify or delet the single views...
Hope it help you reggards