我在Codeigniter上關注這個基本的tutorial關於靜態頁面的服務。我跟所有的步驟,我在這一個:Codeigniter視圖與索引
class Pages extends CI_Controller {
public function view($page = 'home')
{
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->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
我複製並粘貼它看到我發的看法,但它給了我一個404 Page Not Found
。我看了其他教程,他們似乎使用索引函數而不是視圖函數。
比如我改變了上面下面,簡單地更名view
到index
:
class Pages extends CI_Controller {
public function index($page = 'home')
{
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->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
現在正常工作。爲什麼教程代碼無法正常工作?
你設置了:$ route ['default_controller'] ='pages/view';? – sinisake
不是。這是如何影響它的? –
你可以學習路由http://www.codeigniter.com/user_guide/general/routing.html –