我正在开发一个包含许多页面的网站,其内容将从数据库中提取。整个网站都是在codeigniter中完成的。
我不想让网址像www.mywebsite.com/pages/1那样。 相反,我想在输入页面内容时由管理员询问网址名称(FURL)。假设管理员输入FURL为:study-programs / animation 然后路径应显示为www.mywebsity.com/study-programs/animation
有什么建议吗?
答案 0 :(得分:0)
1)Foreach页面存储页面名称(可以使用 uri_title())
2)在路线( application / config / routes )中添加类似的内容;
$route['page/(:any)'] = "pages/page_lookup";
3)在页面控制器中;
<?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);
}
}
有关详细信息,请查看Codeigniter手册中的examples。