[英]Silex autoload my namespace
The site is using Silex. 该网站正在使用Silex。
Structure look like this: 结构如下所示:
root
api
RSYWX
Book.php
vendor
views
web
In Book.php
: 在
Book.php
:
namespace RSYWX;
class Book {
public static function sayHello()
{
return "Hello, there!";
}
}
In composer.json
: 在
composer.json
:
{
"require": {
"silex/silex": "~1.1",
"twig/twig": "^1.23",
"doctrine/dbal": "~2.2",
"symfony/var-dumper": "^2.7"
},
"autoload": {
"psr-4": {
"RSYWX\\": "/api/RSYWX"
}
}
}
I ran composer update
to update the autoload relevant files, in particular the vendor/composer/autoload_psr4.php
: 我运行了
composer update
来更新自动加载相关文件,尤其是vendor/composer/autoload_psr4.php
:
return array(
...
'RSYWX\\' => array('/api/RSYWX'),
...
When I tried to call sayHello
from index.php
file, the error log has this line: 当我尝试从
index.php
文件调用sayHello
,错误日志显示以下行:
PHP Fatal error: Class 'RSYWX\\Book' not found in vagrant/api.rsywx.com/web/index.php on line 32
Any hints to load this class and the static method? 有什么提示可以加载此类和静态方法吗?
Try with: 尝试:
"RSYWX\\": "api/RSYWX"
Because using /
on beginning refers to server's root directory and it's probably not what you wanted. 因为在开始使用
/
指服务器的根目录,可能不是您想要的。 Of course call composer update
after changing composer.json
file. 当然,在更改
composer.json
文件后调用composer update
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.