与作曲家自定义名称空间中的自动加载嵌套文件夹类
我有这些目录和文件结构。
我想在模型名称空间中加载我的 wtf类。
实际上,我想将一些提供商添加到我的项目中,并想将它们定位在自己的文件夹中以进行分类,但要用一个 namespace 将其称为
可能吗?
.
├── composer.json
├── index.php
├── src
│ ├── Controllers
│ │ └── GameController.php
│ ├── Game
│ │ └── Game.php
│ ├── Models
│ │ ├── Game.php
│ │ └── Wtf
│ │ └── Wtf.php
│ └── Player
│ └── Player.php
└── vendor
├── autoload.php
└── composer
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
├── ClassLoader.php
└── LICENSE
错误
[500]: GET / - Uncaught Error: Class 'Rp76\Models\Wtf' not found in /home/reza/www/wtf/index.php:13
Stack trace:
#0 {main}
thrown in /home/reza/www/wtf/index.php on line 13
composer.json
{
"autoload": {
"psr-4": {
"Rp76\\": "src/"
}
}
}
index.php
<?php
use Rp76\Game\Game;
use Rp76\Controllers\GameController;
use Rp76\Player\Player;
require_once "vendor/autoload.php";
new Game();
new Player();
new GameController();
new \Rp76\Models\Game();
new \Rp76\Models\Wtf();
wtf.php
<?php
namespace Rp76\Models;
class Wtf
{
public function __construct()
{
echo 'Wtf<br/>';
}
}
i have these directory and file structure.
i want to load my Wtf class in Models namespace.
in fact i want to add some providers to my project and want to locate them in own folder for classify them but call them with one namespace
its possible?
.
├── composer.json
├── index.php
├── src
│ ├── Controllers
│ │ └── GameController.php
│ ├── Game
│ │ └── Game.php
│ ├── Models
│ │ ├── Game.php
│ │ └── Wtf
│ │ └── Wtf.php
│ └── Player
│ └── Player.php
└── vendor
├── autoload.php
└── composer
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
├── ClassLoader.php
└── LICENSE
Error
[500]: GET / - Uncaught Error: Class 'Rp76\Models\Wtf' not found in /home/reza/www/wtf/index.php:13
Stack trace:
#0 {main}
thrown in /home/reza/www/wtf/index.php on line 13
composer.json
{
"autoload": {
"psr-4": {
"Rp76\\": "src/"
}
}
}
index.php
<?php
use Rp76\Game\Game;
use Rp76\Controllers\GameController;
use Rp76\Player\Player;
require_once "vendor/autoload.php";
new Game();
new Player();
new GameController();
new \Rp76\Models\Game();
new \Rp76\Models\Wtf();
Wtf.php
<?php
namespace Rp76\Models;
class Wtf
{
public function __construct()
{
echo 'Wtf<br/>';
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论