【问题标题】:How to URL rewrite in CodeIgniter?如何在 CodeIgniter 中重写 URL?
【发布时间】:2015-09-02 10:52:12
【问题描述】:

我的路线配置仅包含以下路线:

$route['default_controller'] = "frontend/home";

我想重写默认路由

http://192.168.1.4/sncraft/frontend/home/about

到这样的网址 http://192.168.1.4/sncraft/about

控制器的内容是:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

    public function __Construct(){
        parent::__Construct();

        $this->load->library('image_lib');
        $this->load->model('frontend/front_model');
    }


    public function index(){
        $config = array();
        $config["base_url"] = base_url()."frontend/home";
        $this->viewForm();
    }   

    public function about(){
        $this->load->view('frontend/header');
        $this->load->view('frontend/about');
        $this->load->view('frontend/footer');
    }   
}

?>

【问题讨论】:

    标签: php codeigniter url-rewriting


    【解决方案1】:

    $route 数组的键是指向控制器功能的实际 url(没有基本 url)。

    您的路线如下所示:

    $route['about'] = "frontend/home/about";
    

    我假设你在家庭控制器中的函数被称为 about()。

    您可以在此处找到更多信息:URI Routing

    【讨论】:

    • 您是否在前端控制器中添加了一个名为 about() 的函数?您收到错误消息吗?
    • 我在控制器 Home 中有一个 about() 函数,在那边没有发现任何错误。我只需要上面显示的 url 重写。
    • 您能否编辑您的问题并添加控制器文件的内容和文件的确切名称,包括路径? CodeIgniter 在文件命名约定方面有点棘手。
    • 请检查我添加了一些新的
    • 看起来您的控制器被称为“Home”。请看一下编辑后的答案。
    猜你喜欢
    • 2013-11-08
    • 2023-04-07
    • 1970-01-01
    • 2016-08-18
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多