FURLS with codeigniter

眉间皱痕 提交于 2020-01-06 20:03:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!