按照教程,就可以辦理通過應用程序/控制器/ pages.php控制器及路線
class Pages extends CI_Controller {
public function view($page = 'home')
{
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('templates/header', $data);
$this->load->view('templates/nav', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/aside_right', $data);
$this->load->view('templates/bottom', $data);
}
}
此作品爲「家」 -page靜態頁面的所有要求,但我不例如,似乎無法調用views/pages /。
我試圖爲about-page製作一個單獨的控制器。它有效,但感覺有點不對。
應用/控制器/ about.php
class About extends CI_Controller {
public function index()
{
$this->load->view('templates/header');
$this->load->view('templates/nav');
$this->load->view('pages/about');
$this->load->view('templates/aside_right');
$this->load->view('templates/bottom');
}
}
我也有我的htaccess的文件或文件路徑的問題。通過上面編寫的About控制器,我只能通過輸入domain.com/index.php/about進入頁面。我想它是domain.com/about等
這是我的routes.php文件的名字:
$route['about'] = 'about';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
我的.htaccess:
RewriteEngine on
RewriteBase/
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
+1,url應該是'domain/pages/about' –
謝謝,現在有很多的清晰!儘管仍然有問題的URL,我只能通過domain.com/index.php/about/而不是domain.com/about或domain.com/pages/about – estrar
@estrar,然後錯誤是在你的' .htaccess'。看看這裏的工作'.htaccess':http://codeigniter.com/user_guide/general/urls.html – Zagorax