我目前正在学习 PHP,并在 MySQL 中使用 XAMPP。当我遇到问题时,这应该是我的第二个代码项目。 XAMPP 控制面板中没有问题,但当我打开 MySQL 时,我在 index.php 中为路由器创建的 try catch 方法捕获了错误。我也尝试在config -> 服务和端口设置中将MySQL的默认端口和Apache的80的端口更改为8080,但仍然没有变化,与更改my.ini中的端口相同。我创建的路由器不用于生产,而是用于学习目的,只是为了更好地理解它。
任何解决方案都会有帮助!谢谢!
require __DIR__ . '/../../vendor/autoload.php';
use App\View;
session_start();
define('STORAGE_PATH', __DIR__ . '/../storage');
define('VIEW_PATH', __DIR__ . '/../views');
try {
$router = new App\Exceptions\Router();
$router
->get('/', [App\Controllers\HomeController::class, 'index'])
->post('/upload', [App\Controllers\HomeController::class, 'upload'])
->get('/invoices', [App\Controllers\InvoiceController::class, 'index'])
->get('/invoices/create', [App\Controllers\InvoiceController::class, 'create'])
->post('/invoices/create', [App\Controllers\InvoiceController::class, 'store']);
echo $router->resolve($_SERVER['REQUEST_URI'], strtolower($_SERVER['REQUEST_METHOD']));
} catch (\App\Exceptions\RouteNotFoundException $e) {
// header('HTTP/1.1 404 Not found');
http_response_code(404);
echo View::make('error/404');
}
假设您使用 RewriteRule 在 vhost 配置文件中构建路由,请在其他重定向规则之前添加以下行,以便系统排除 phpmyadmin 目录:
RewriteRule ^(phpmyadmin)($|/) - [L]
因此,如果您当前的虚拟主机是这样的:
Options FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)?$ web/$1
然后,将其更改为:
Options FollowSymlinks
RewriteEngine on
RewriteRule ^(phpmyadmin)($|/) - [L]
RewriteRule ^(.+)?$ web/$1