0

Basicly I have a contreller that named site.php , and have views:header.php,nav.php,content.php,footer.php etc. problem is how can run content_about.php? Im trying this url:site/about but I get an error on browser! Code is that:

<?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");
    }
}
4

1 回答 1

2

试试这个。

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

在视图中制作 template.php 并将这些行

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

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

于 2013-06-28T08:51:48.593 回答