我是新手。我终于可以让我的网站显示带有 MY_Controller.php 的页面,但页脚和页眉部分除外。
这是我的 MY_Controller.php:
class MY_Controller extends CI_Controller {
protected $data = array();
function __construct() {
parent::__construct();
}
function render_page($view) {
//do this to don't repeat in all controllers...
$this->load->view('templates/header', $this->data);
//menu_data must contain the structure of the menu...
//you can populate it from database or helper
$this->load->view($view, $this->data);
$this->load->view('templates/footer', $this->data);
}
还有我的家庭控制器:
class Home extends MY_Controller {
function __construct() {
parent::__construct();
}
public function view($page = 'home')
{
$this->load->helper('text');
$data['records']= $this->services_model->getAll();
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('pages/'.$page, $data);
}
配置/config.rb:
$config['index_page'] = 'index.php';
$config['subclass_prefix'] = 'MY_';
配置/路由.rb:
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
在源代码中,我只能看到 home.php 代码。未加载 header 和 footer.php 代码。你有什么建议?