2013-01-24 28 views
2
<?php 
class Page extends CI_Controller{ 

    function index(){ 
     $this->view('home'); 
    } 

    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('pages/'.$page, $data); 
     $this->load->view('templates/footer', $data); 

    } 

我要查看的鏈接作爲http://www.mydomain.com/page/abouthttp://www.mydomain.com/page/services等頁面不格式的靜態頁面http://www.mydomain.com/page/view/abouthttp://www.mydomain.com/page/view/services查看在笨

我怎麼可以這樣做?

回答

5

config/routes.php您可以添加一個路線:

$route['page/(:any)'] = "/page/view/$1"; 
+0

請幫忙查一下我的問題http://stackoverflow.com/questions/39360697/link-to-view-inside-subfolder-does-未顯示正確 – 2016-09-07 04:55:28

3

在/config/route.php中爲您的特定靜態頁面設置路由。

$route['contact'] = 'site/page/contact';