简体   繁体   English

子文件夹中的 Codeigniter 3 控制器无法在实时服务器上运行

[英]Codeigniter 3 controller in subfolder not working on live server

I'm using CI 3.1.11我正在使用 CI 3.1.11

I got some problem when developed my app, which is I use CI.开发我的应用程序时遇到了一些问题,即我使用 CI。 I try to create a new folder in /app/controller/ on CI.我尝试在 CI 上的/app/controller/创建一个新文件夹。 Which one is /Admin to optimize my code.哪一个是/Admin来优化我的代码。 So, my file looks like this :所以,我的文件看起来像这样:

--CONTROLLER
  --Admin
     Home.php
     User.php
  --Student
     Home.php
     Study.php
  Homepage.php
  Another.php

On local在本地

http://localhost/myweb/admin/home
http://localhost/myweb/student/home

Its work.这是工作。

BUT, when I try to host my site但是,当我尝试托管我的网站时

http://sub.domain.com/admin/home
http://sub.domain.com/student/home

Its broken not found page 404.它的损坏未找到第 404 页。

. . . . I test to set route.php on live server like :我测试在实时服务器上设置 route.php,如:

$route['testpage'] = 'admin/home';

So I try,所以我尝试,

http://sub.domain.com/testpage

Been stuck with this issue for 2 days, and i found my solution as such :被这个问题困扰了 2 天,我找到了我的解决方案:

if you have folder structure like below :如果您有如下文件夹结构:

--CONTROLLER
  --Admin
     Home.php
     User.php
  --Student
     Home.php
     Study.php
  Homepage.php
  Another.php

you should define your routes in routes.php like this :你应该像这样在routes.php 中定义你的路由:

// for 'Admin' folder 
$route['testpage'] = "Admin/home";
$route['testpage/(:any)'] = "Admin/$1"; // to target Subfolder and other controller
$route['testpage/(:any)/(:any)'] = "Admin/$1/$2"; // to target controllers function
$route['testpage/(:any)/(:any)/(:any)'] = "Admin/$1/$2/$3"; // to target controller function parameters

Note that the folder name definition is capital letter (i think this is depend on server or php.ini configuration, not sure about it)请注意,文件夹名称定义是大写字母(我认为这取决于服务器或 php.ini 配置,不确定)

in this case your subdomain will be :在这种情况下,您的子域将是:

http://sub.domain.com/testpage

I'm using Codeigniter 3.1.11 with PHP 7.3我在PHP 7.3 中使用Codeigniter 3.1.11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM