apache / laragon+作曲家自动加载问题
我刚刚开始尝试创建一个简单的路由器(我尝试了几种解决方案,例如Altorouter,而没有奏效,我想启动一个非常简单的解决方案)。 作曲家自动加载无法达到命名空间。
致命错误:未被发现的错误:c:\ laragon \ www \ router \ router \ index.php中找不到类'app \ router' \ index.php在第6行
上
我做了“作曲家转储 - autoload”和“作曲家更新命令”,甚至尝试了一个自制的自动加载器。
这是我项目的架构:
- 路由器
src
>路由器
路由器
路线
供应商
自动加载
- .htaccess
- index.php
- composer.json
- composer.lock
作曲家
{
"name": "root/router",
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"authors": [
{
"name": "********",
"email": "************"
}
],
"require": {}
}
这是
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
我
<?php
require './vendor/autoload.php';
use App\Router;
$router = new Router($_GET[$url]);
$router->get('/home', function(){ echo 'welcome on home page'; });
$router->run();
的
<?php
namespace App;
use App\Route;
class Router {
public $url;
private $routes = [];
public function __construct($url)
{
$this->url = $url;
}
public function get($path, $callable)
{
$route = new Route($path, $callable);
$this->routes['GET'][] = $route;
}
public function post($path, $callable)
{
$route = new Route($path, $callable);
$this->routes['POST'][] = $route;
}
public function run()
{
echo '<pre>';
echo print_r($this->routes);
echo '</pre>';
}
}
。
<?php
namespace App;
class Route {
public function __construst($path, $callable)
{
$this->path = $path;
$this->callable = $callable;
}
}
I just started an attempt to create a simple Router (I tried several solutions like AltoRouter and as nothing worked, I wanted to started a very simple one).
The Composer autoload can't reach the namespace.
Fatal error: Uncaught Error: Class 'App\Router' not found in C:\laragon\www\router\index.php:6 Stack trace: #0 {main} thrown in C:\laragon\www\router\index.php on line 6
I did the "composer dump-autoload" and the "composer update commands" and even tried an home made autoloader.
Here is the architecture of my project :
- router
src
> Router
Router
Route
vendor
autoload
- .htaccess
- index.php
- composer.json
- composer.lock
Here is my composer.json
{
"name": "root/router",
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"authors": [
{
"name": "********",
"email": "************"
}
],
"require": {}
}
Here is my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Here is my index.php
<?php
require './vendor/autoload.php';
use App\Router;
$router = new Router($_GET[$url]);
$router->get('/home', function(){ echo 'welcome on home page'; });
$router->run();
Here is my Router class
<?php
namespace App;
use App\Route;
class Router {
public $url;
private $routes = [];
public function __construct($url)
{
$this->url = $url;
}
public function get($path, $callable)
{
$route = new Route($path, $callable);
$this->routes['GET'][] = $route;
}
public function post($path, $callable)
{
$route = new Route($path, $callable);
$this->routes['POST'][] = $route;
}
public function run()
{
echo '<pre>';
echo print_r($this->routes);
echo '</pre>';
}
}
Here is my Route.php class
<?php
namespace App;
class Route {
public function __construst($path, $callable)
{
$this->path = $path;
$this->callable = $callable;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题可能是命名空间。
尝试以下操作:
然后键入
作曲家dump-autoload
I think the problem might be the namespace.
Try this:
then type
composer dump-autoload