CodeIgniter 4只有默认路由/可访问,如果我在Routes.php中定义,则没有其他路由可用.我使用的是ubu



app/.htaccess和项目目录中的我的.htacccess文件就在这里。两者都一样。我使用的是相同的.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('AppControllers');
$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';
}

开/它工作正常。但在测试中,它给了我错误。

在此服务器上找不到请求的URL。我该如何解决这个问题。我的index.php运行良好。

试试这个

$routes->get('/test','App\Controllers\Home::test'(;

但要实现这一点,您需要在Controllers文件夹中有一个名为Home的Controller,并且在控制器中也有一个名称为test的方法。

在您的家庭控制器中,是否有的方法

return view('test');

echo view('test');

或者您想访问文件夹测试并查看它们?如果是,请检查View中是否有文件夹名称测试,以及文件夹测试中是否有test.php?如果你检查过了,所有的都存在,那么你就可以写这样的代码

return view('/test/test');

echo view('/test/test');

既然你没有给我们展示一个完整的代码,这就是我的猜测。希望这能解决问题。

相关内容

  • 没有找到相关文章

最新更新