问题
I am developing a website with many pages whose content will be fetched from database. The whole website is done in codeigniter.
I do not want to have url's like www.mywebsite.com/pages/1 or something. Rather I would like to have url name (FURL) asked by the administrator at the time of entering the contents of the page. Suppose the admin enters FURL as : study-programs/animation then the path should be shown as www.mywebsity.com/study-programs/animation
Any suggestions?
回答1:
1) Foreach page store the page name (could use uri_title())
2) In the routes (application/config/routes) add something like;
$route['page/(:any)'] = "pages/page_lookup";
3) In the pages controller;
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function page_lookup($page) {
// do your database query getting page id where page name = $page
$result = $this->page_model->get_page_by_name($page);
// $result could hold the page html
// if so, then just do
$this->load->view($result);
}
}
For more details look at the examples in the Codeigniter manual.
来源:https://stackoverflow.com/questions/10845440/furls-with-codeigniter