php - CodeIgniter 4 只有默认路由 / 是可访问的,如果我在我的 Routes.php 中定义,则没有其他路由可用。我正在使用 ubuntu
问题描述
我在 app/.htaccess 和项目目录中的 .htaccess 文件在这里。两者都是一样的。我正在使用相同的 .htaccess 文件,该文件存在于应用程序和项目目录的公共目录中
Routes.php 在这里
<?php
namespace Config;
// Create a new instance of our RouteCollection class.
$routes = Services::routes();
// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
{
require SYSTEMPATH . 'Config/Routes.php';
}
/**
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);
/**
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/test', 'Home::test');
$routes->get('/test', 'Home::test');
/**
* --------------------------------------------------------------------
* Additional Routing
* --------------------------------------------------------------------
*
* There will often be times that you need additional routing and you
* need it to be able to override any defaults in this file. Environment
* based routes is one such time. require() additional route files here
* to make that happen.
*
* You will have access to the $routes object within that file without
* needing to reload it.
*/
if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'))
{
require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
开/它工作正常。但是在 /test 上它给了我错误。
在此服务器上找不到请求的 URL。我该如何解决这个问题。我的 index.php 工作正常。
解决方案
尝试这个
$routes->get('/test', 'App\Controllers\Home::test');
但要使其工作,您需要在 Controllers 文件夹中有一个名为 Home 的控制器,并且在控制器内还有一个名为 test 的方法。
推荐阅读
- python - 如何在循环中使用 Scrapy FormRequest
- javascript - 由于多个选择声明而导致功能损坏
- javascript - Mongoose 模型查询挂在节点中
- vb.net - Visual Basic 解析子节点
- bash - 在斐波那契数列中查找数字的索引
- powershell - 最小化远程服务器时的 PowerShell 屏幕截图
- android - 不兼容的类型:Fragment 无法转换为 Activity
- java - 我需要一个会写 Java Streams 的人。我想将此代码编写为 Java 流类型
- typescript - 本地打字稿包的导入未解决
- javascript - 为什么我必须使用高阶函数作为 setTimeout 中的第一个参数?