douduiti3040 2013-12-13 16:18
浏览 48
已采纳

路由控制器覆盖

I am developing a website using the MVC pattern with the CodeIgniter framework.

I have 2 controllers:

Site - Main Controller Navigates In Views

class Site extends CI_Controller {
    public function index() {
        $this->view ();
    }
    public function view($page = 'home') {
        if (! file_exists ( "application/views/pages/$page.php" )) {
            show_404 ();
        }
        $data ['page'] = 'pages/' . $page;
        $this->load->view ( 'template/template.php', $data );
    }
}

Members - Controller for managing membership system

class Members extends CI_Controller {
    public function __construct() {
        $this->load->model ( "members_model" );
    }
    public function login() {
        $this->members_model->login ();
    }
}

My Routes Config

$route ['default_controller'] = "site";
$route ['(:any)'] = "site/view/$1";

So now I have a little problem which is when I call the members controller, it'll look for a page named members and not a controller named members.

What can I do to fix that?

  • 写回答

2条回答 默认 最新

  • duan5362 2013-12-13 16:23
    关注

    you have to create other route for Members

    $route ['members'] = "members";
    $route ['members/(:any)'] = "members/$1";
    $route ['default_controller'] = "site";
    $route ['(:any)'] = "site/view/$1";
    

    note that order is matter, the route above will use members first when matched route detected.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题