使用Codeigniter框架进行导航

时间:2013-06-28 08:44:22

标签: php

基本上我有一个名为site.php的contreller,并且有视图:header.php,nav.php,content.php,footer.php等问题是怎么运行content_about.php的? 我正在尝试这个网址:网站/关于但我在浏览器上收到错误! 代码是:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class site extends CI_Controller {

    public function index()
    {
        $this->home();
    }
    public function home()
    {
        $this->load->view("site_header");
        $this->load->view("site_nav");
        $this->load->view("content_home");
        $this->load->view("site_footer");
    }
    public function about()
    {
        $this->load->view("site_header");
        $this->load->view("site_nav");
        $this->load->view("content_about");
        $this->load->view("site_footer");
    }
}

1 个答案:

答案 0 :(得分:2)

试试这个。

public function about()
{
    $data=array();
    $data['main']='content_about'; //only the content part without header,nav and footer
    $this->load->view('template',$data);
}

在视图中make template.php并放置这行

<?=$this->load->view('site_header.php');?>
<?=$this->load->view('site_nav.php');?>
<?=$this->load->view($main);?>
<?=$this->load->view('site_footer');?>

如果您遇到任何问题,请告诉我。