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

[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">
    &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!


Messages In This Thread
PHP basic to CI? - by El Forum - 05-30-2009, 07:02 AM
PHP basic to CI? - by El Forum - 05-30-2009, 07:40 AM
PHP basic to CI? - by El Forum - 05-30-2009, 07:53 AM
PHP basic to CI? - by El Forum - 05-30-2009, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB