我在packagist上创建了一个用于学习的简单包(tommytest / tommytest)。 它安装得很好,但我必须在安装后立即运行“ composer dump-autoload -o strong>”。 在手动运行dump-autoload之前,我得到了这个: p>
致命错误:在C:\ xampp \ htdocs \ simple \ index.php中找不到类'mysqlgridspace \ Page' 第5行 strong> p>
手动运行dump-autoload后,它可以正常工作。 是不是应该在安装软件包时自动处理自动加载设置? p>
这是我的composer.json(位于: simple / vendor / tommytest / tommytest / composer.json strong>) p>
我的班级文件(位于: simple / vendor / tommytest / tommytest / src / Mysqlgridmain.class.php strong>) p>
{
“name”:“tommytest / tommytest”,
“type”:“library”,
“description” :“框架无关数据网格”,
“关键字”:[“datagrid”,“数据网格”],
“主页”:“https://github.com/escalibore/tommytest",
”license“ :“麻省理工学院”,
“作者”:[
{
“name”:“Tommy Bert”,
“email”:“tom@tberthold.com”,
“主页”:“http:/ /tberthold.com",n“角色”:“开发人员”
}
,
“要求”:{
“php”:“> = 5.3.0”
},
“ autoload“:{
”psr-4“:{
”mysqlgridspace \\“:”src /“
}
}
}
code> pre>
<?php
namespace mysqlgridspace;
class Page {
public function __construct()
{
echo“你好,我是一个页面。< br>”;
}
}
class Book {
public function __construct()
{
echo“hello,我是一本书。< br>“;
}
}
code> pre>
div>
I have created a simple package on packagist for learning (tommytest/tommytest). It installs fine, but I have to run "composer dump-autoload -o" immediately after it is installed. Before manually running the dump-autoload I get this:
Fatal error: Class 'mysqlgridspace\Page' not found in C:\xampp\htdocs\simple\index.php on line 5
After manually running dump-autoload it works fine. Isn't it supposed to handle the autoload set-up automatically when the package is installed?
Here's my composer.json (located in: simple/vendor/tommytest/tommytest/composer.json)
{
"name": "tommytest/tommytest",
"type": "library",
"description": "Framework agnostic data grid",
"keywords": ["datagrid","data grid"],
"homepage": "https://github.com/escalibore/tommytest",
"license": "MIT",
"authors": [
{
"name": "Tommy Bert",
"email": "tom@tberthold.com",
"homepage": "http://tberthold.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"mysqlgridspace\\":"src/"
}
}
}
And my class file (located in: simple/vendor/tommytest/tommytest/src/Mysqlgridmain.class.php)
<?php
namespace mysqlgridspace;
class Page {
public function __construct()
{
echo "hello, i am a page.<br>";
}
}
class Book {
public function __construct()
{
echo "hello, i am a book.<br>";
}
}