Welcome Guest, Not a member yet? Register   Sign In
PHP basic to CI?
#1

[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">
&lt;html &gt;

&lt;head&gt;
    &lt;title&gt;Artisan Websolutions&lt;/title&gt;
    &lt;link rel="SHORTCUT ICON" href="images/favicon.png" /&gt;
    &lt;meta http-equiv="content-type" content="text/html;charset=utf-8" /&gt;
&lt;/head&gt;

&lt;body&gt;
<div id="global_wrapper">
    <div id="wrapper">
        <div id="nav_top">
            <div class="nav_left"></div>
            <div class="nav_mid">
                &lt;?php include("includes/nav.php");?&gt;
            </div>
            <div class="nav_right"></div>
        </div>
        <div id="cont_wrapper">
            <div class="cont_upper"></div>
            <div class="cont_mid">
                <div id="cont_main">
                    &lt;?php
                        $default ='home';
                        $page = isset($_GET['page']) ? $_GET['page'] : $default;
                        if (!file_exists('includes/'.$page.'.php')) {
                            echo 'no such file';
                        }
                        include('includes/'.$page.'.php');
                    ?&gt;
                </div>
            </div>
            <div class="cont_lower"></div>
        </div>
        <div id="footer">&lt;?php include("includes/footer.php")?&gt;</div>
    </div>
</div>
&lt;/body&gt;
&lt;/html&gt;

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.
#2

[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:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title>
&lt;/head&gt;
&lt;body&gt;
<div id="mainNav">
    &lt;?php $this->load->view('partials/mainNav'); ?&gt;
</div>
<div id="content">
    &lt;!-- My content --&gt;
</div>
&lt;/body
&lt;/html>
#3

[eluser]JingCleoVil[/eluser]
Ok thanks.let me try using the code you provided.
#4

[eluser]JingCleoVil[/eluser]
I try but something wrong with nav.Here is what I did.

controller/welcome.php
Code:
&lt;?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:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?= $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<ul class="navigation">
    &lt;?php foreach($nav_list  as $i => $nav_item): ?&gt;
        <li class="&lt;?= ($nav == $nav_item ? 'selected' : '')?&gt;">
            &lt;?= anchor($nav_item, $nav_item) ?&gt;
        </li>
    &lt;?php endforeach ?&gt;
</ul>
    <div id="contents">&lt;?= $contents ?&gt;</div>
    <div id="footer">Copyright 2008</div>
&lt;/body&gt;
&lt;/html&gt;

library/Template.php
Code:
&lt;?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">&lt;?= $contents ?&gt;</div>" the page will goes to http://localhost/myci/index.php/about and says 404 error. thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB