带代码指示器的FURLS [英] FURLS with codeigniter
问题描述
我正在开发一个网站,其中包含许多网页,其内容将从数据库中提取。整个网站是用codeigniter完成的。
我不想拥有像www.mywebsite.com/pages/1这样的网址。
而是我想在输入页面内容的时候有管理员要求的URL名称(FURL)。假设管理员输入FURL为:study-programs / animation
,则路径应显示为www.mywebsity.com/study-programs/animation
任何建议?
1)Foreach页面存储页面名称(可以使用 uri_title() / p>
2)在路由中( application / config / routes )添加类似
$ route ['page /(:any)'] =pages / page_lookup;
3)在页面控制器中;
<?php if(!defined('BASEPATH'))exit('不允许直接脚本访问);
类扩展CI_Controller {
public function __construct(){
parent :: __ construct();
}
public function page_lookup($ page){
//执行数据库查询获取页面id其中页面名称= $ page
$ result = $ this- > page_model-> get_page_by_name($ page);
// $ result可以保存页面html
//如果是这样,那么只需
$ this-> load-> view($ result);
}
}
有关详细信息,请参阅示例。
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) 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.
这篇关于带代码指示器的FURLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!