用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5912|回复: 3
收起左侧

[控制器] CI4 无法访问控制器子目录 急

[复制链接]
发表于 2020-6-23 15:32:33 | 显示全部楼层 |阅读模式
本帖最后由 fykknd 于 2020-6-23 15:39 编辑

问题描述:我访问例子的Home可以正常访问,但是将Home放入自定义的子控制器文件夹就无法访问,并报错

我的目录结构:app
  ┗━━Controllers
              ┗━━━━Commons
                                ┗━Home.php


访问URL:http://127.0.0.1:20206/
访问 http://127.0.0.1:20206/Commons/Home/ 也不行
app/Config/Routes.php路由里只有一条:
PHP复制代码
 
$routes->get('/', 'Commons\Home');
 
 
复制代码


Nginx虚拟服务器配置:(确实指向了public,不然也无法访问Home)

  1.     server {
  2.         listen       20206;

  3.         access_log  logs/c4.access.log;
  4.         error_log    logs/c4.error.log    error;

  5.         root    "D:/www/c4/public";
  6.         location / {
  7.             try_files $uri $uri/ /index.php/$args;
  8.             index  index.php index.htm index.html;
  9.         }

  10.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  11.         location ~ \.php(.*)$  {
  12.             fastcgi_pass   127.0.0.1:9000;
  13.             fastcgi_index  index.php;
  14.             fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
  15.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  16.             fastcgi_param  PATH_INFO  $fastcgi_path_info;
  17.             fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
  18.             include        fastcgi_params;
  19.         }

  20.     }

复制代码









发表于 2021-5-27 11:09:28 | 显示全部楼层
先检查命名空间
发表于 2021-6-1 23:15:31 | 显示全部楼层
PHP复制代码
namespace App\Controllers\Commons;
use CodeIgniter\Controller;
 
class Home extends Controller{
 
        public function index(){
                echo 1111;exit;
        }
 
}
复制代码


你需要这样子
发表于 2021-8-2 09:44:16 | 显示全部楼层
PHP复制代码
 
namespace App\Controllers\Commons;
use CodeIgniter\Controller;
 
class Home extends Controller{
 
        public function index(){
                echo 1111;exit;
        }
 
}
 
 
$routes->get('/', 'Commons/Home::index');
 
 
复制代码

本版积分规则