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