我是一个新手,并试图更多地了解CI。昨天我试图实现MY_Controller.php。我阅读用户指南中的说明但我无法得到它的优点是什么?还有一件事我不明白这个想法使用它。 我写的应用程序/核心/ MY_Controller.phpCodegniter能告诉我关于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);
}
}
这我家的控制器应用程序/控制器/ home.php
class Home extends MY_Controller {
public function view($page = 'home')
{
$this->load->helper('text');
$this->data['records']= $this->services_model->getAll();
if (! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->render_page('pages/'.$page)
}
}
和我的看法是,在我的应用程序/视图/页/家.PHP。 的config/routes.php文件:
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
现在我得到404分error.My的问题是:
1)为什么我得到404错误? 2)如果我添加关于页面,我应该添加一个新的控制器或使用家庭控制器?
在使用my_Controller.php之前,我使用了页面控制器。我再次没有使用索引作为函数,但我得到了意见?你确定? – ytsejam 2012-08-02 06:35:46