Codeignator使子目录控制器工作 [英] Codeigniter making sub-directory controllers work

查看:162
本文介绍了Codeignator使子目录控制器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使页面加载控制器,我也想要它。



例如,我希望我的网站加载为localhost / sitename / catergory1 / catergory2其中catergory 1是其自己的控制器,2是一种方法。所以我试过添加到我的routes.php:

  $ route ['catergory1'] ='catergory1 / cat1' ;我的控制器文件设置为:




< -Controller


    -Home.php

    -catergory1 < - 子文件夹

        .php

我认为会导致codeigniter加载控制器'cat1'在catergory 1文件夹,而是当我去localhost / sitename / catergory1它只是加载我的默认控制器'家'。我试过把它在uri路由和保留路由部分routes.php,但它仍然不会工作。这可能是真的很容易,但新的这一点。



控制器本身只是与它们有关:

家庭控制器:

  class Home extends CI_Controller {
function index(){
$ this-> load-> view('home');
}
}

Cat1控制器:



class Cat1 extends CI_Controller {
function index(){
$ this-> load-> view('cat1');
}
}

我只是愚蠢, br>
谢谢。

解决方案

category1 btw。



如果我正确追踪您的结构:

  \控制器
- home.php
\ category1 \
- cat1.php

如果是这样,你对自己的路线感到困惑:

  $ route ['category1'] ='category1 / cat1 / index'; 

需要定义方法 index 是基于你的'cat1.php'文件是:

  class Cat1 extends CI_Controller {
function index
$ this-> load-> view('cat1');
}
}



我写了这个,因为人们通常会感到困惑CI中的路线:

http:// blog.biernacki.ca/2011/12/codeigniter-uri-routing-issue-with-controller-folders/


I'm having trouble making the page load the controller I want it too.

For example I want my site to load as localhost/sitename/catergory1/catergory2 where catergory 1 is its own controller and 2 is a method. So i've tried adding this to my routes.php:

$route['catergory1'] = 'catergory1/cat1';

with my controller file set up as:
-Controller
   -Home.php
   -catergory1 <- subfolder
       -cat1.php
which I thought would cause codeigniter to load the controller 'cat1' inside the catergory 1 folder but instead when I go to localhost/sitename/catergory1 it just loads my default controller 'home'. I've tried putting it in both the uri routes and reserved routes part of routes.php but it still won't work. It's probably something really easy but im new to this.

Heres the controllers themselves just incase its something to do with them:
home controller:

class Home extends CI_Controller {  
    function index() {  
        $this->load->view('home');  
    }
}

Cat1 controller:

class Cat1 extends CI_Controller{  
    function index() {  
        $this->load->view('cat1');  
    }  
}

Am i just being stupid and missing something easy?
Thanks.

解决方案

You have a typo in category1 btw.

If I follow correctly you have this structure:

\ controllers
 - home.php
 \ category1 \
  - cat1.php

If so, you confused yourself with your route:

$route['category1 '] = 'category1/cat1/index';

Need to define the method index, this is based on your 'cat1.php' file being:

class Cat1 extends CI_Controller{
   function index() {
      $this->load->view('cat1');
   }
}

I wrote about this, as people usually get confused with routes in CI:
http://blog.biernacki.ca/2011/12/codeigniter-uri-routing-issue-with-controller-folders/

这篇关于Codeignator使子目录控制器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆