PHP basic to CI? - El Forum - 05-30-2009
[eluser]JingCleoVil[/eluser]
I am new from CI this is just I wanted to know to have a Master Page so that i will not redundantly make the layout in all pages. Here is my basic code.
index.php - This is my Master Page.
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<title>Artisan Websolutions</title>
<link rel="SHORTCUT ICON" href="images/favicon.png" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<div id="global_wrapper">
<div id="wrapper">
<div id="nav_top">
<div class="nav_left"></div>
<div class="nav_mid">
<?php include("includes/nav.php");?>
</div>
<div class="nav_right"></div>
</div>
<div id="cont_wrapper">
<div class="cont_upper"></div>
<div class="cont_mid">
<div id="cont_main">
<?php
$default ='home';
$page = isset($_GET['page']) ? $_GET['page'] : $default;
if (!file_exists('includes/'.$page.'.php')) {
echo 'no such file';
}
include('includes/'.$page.'.php');
?>
</div>
</div>
<div class="cont_lower"></div>
</div>
<div id="footer"><?php include("includes/footer.php")?></div>
</div>
</div>
</body>
</html>
nav.php - my main navigation
Code: <ul id="navigation">
<li><a href="?page=home"><span><img src="images/home_n.png"></span></a></li>
<li><a href="?page=aboutus"><span><img src="images/aboutus.png"></span</a></li>
</ul>
home.php - my main page
Code: <div class="main_content">
<h1>My Main Page</h1>
<p>Blah blah blah</p>
</div>
home.php - About US
Code: <div class="main_content">
<h1>About Us</h1>
<p>Blah blah blah</p>
</div>
Its obviously when you click "about us" link the page will display here
Code: <div id="cont_main">
?php
$default ='home';
$page = isset($_GET['page']) ? $_GET['page'] : $default;
if (!file_exists('includes/'.$page.'.php')) {
echo 'no such file';
}
include('includes/'.$page.'.php');
</div>
Now I just wanted to do a basic CI code to make this thing happen same process but CI made .Thanks!
PS: SOrry for my English.
PHP basic to CI? - El Forum - 05-30-2009
[eluser]derekmichaeljohnson[/eluser]
This is indeed a popular question.
Try http://maestric.com/en/doc/php/codeigniter_template
You can also load views within views like so:
Code: <html>
<head>
<title></title>
</head>
<body>
<div id="mainNav">
<?php $this->load->view('partials/mainNav'); ?>
</div>
<div id="content">
<!-- My content -->
</div>
</body
</html>
PHP basic to CI? - El Forum - 05-30-2009
[eluser]JingCleoVil[/eluser]
Ok thanks.let me try using the code you provided.
PHP basic to CI? - El Forum - 05-30-2009
[eluser]JingCleoVil[/eluser]
I try but something wrong with nav.Here is what I did.
controller/welcome.php
Code: <?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$this->template->set('nav', 'About');
$this->template->set('title', 'About me');
$this->template->load('template', 'about');
}
}
view/template.php
Code: <html>
<head>
<title><?= $title ?></title>
</head>
<body>
<ul class="navigation">
<?php foreach($nav_list as $i => $nav_item): ?>
<li class="<?= ($nav == $nav_item ? 'selected' : '')?>">
<?= anchor($nav_item, $nav_item) ?>
</li>
<?php endforeach ?>
</ul>
<div id="contents"><?= $contents ?></div>
<div id="footer">Copyright 2008</div>
</body>
</html>
library/Template.php
Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template {
var $template_data = array();
function set($name, $value)
{
$this->template_data[$name] = $value;
}
function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
$this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
return $this->CI->load->view($template, $this->template_data, $return);
}
}
All things works fine on Loading but when you click the link it will not Received by "$contents" and it goes to 404 error.
Instead of loading here "<div id="contents"><?= $contents ?></div>" the page will goes to http://localhost/myci/index.php/about and says 404 error. thanks again!
|