0
我是一個新手。我終於可以使我的網站顯示除了頁腳和頁眉部分之外的頁面。Codeigniter MY_Controller不會加載頁眉/ footer.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_';
的config/routes.rb中:
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
在源代碼中,我只能看到home.php代碼。 header和footer.php代碼不會被加載。你有什麼建議?
.rb?真? :) – 2012-08-02 09:49:35
我也在Ruby on rails上開發:) – ytsejam 2012-08-02 12:50:03