Symfony服务模式
我正在尝试在symfony2中配置服务: 服务.yml 我有一个错误:Symfony服务模式,symfony,Symfony,我正在尝试在symfony2中配置服务: 服务.yml 我有一个错误: ClassNotFoundException: Attempted to load class "TrendioRest" from namespace "Trendio\DelivBundle\Services" in /var/www/deliv/app/cache/dev/appDevDebugProjectContainer.php line 3176. Do you need to "use" it from an
ClassNotFoundException: Attempted to load class "TrendioRest" from namespace "Trendio\DelivBundle\Services" in /var/www/deliv/app/cache/dev/appDevDebugProjectContainer.php line 3176. Do you need to "use" it from another namespace?
TrendioRest.php
但,若我将类移动到顶级绑定名称空间Trendio\DeliverBundle,服务将正常工作。为什么类不从子文件夹名称空间加载 使用Symfony类是最佳实践 因为您可以这样简化它:
parameters:
trendio.rest.backend_ip: 192.168.0.102
services:
_defaults:
autowire: true
Trendio\DelivBundle\TrendioUserProvider: ~
Trendio\DelivBundle\Services\TrendioRest:
arguments: [%trendio.rest.backend_ip%]
能否指定包含TrendioRest类的文件的路径?是否按照PSR-0进行放置?如果使用Symfony2而不进行任何自定义,则路径应为/src/Trendio/delivebundle/Services/TrendioRest.phpYes,路径为{root}/src/Trendio/delivebundle/Services/TrendioRest.php
<?php
namespace Trendio\DelivBundle\Services;
class TrendioRest { ... }
parameters:
trendio.rest.backend_ip: 192.168.0.102
services:
_defaults:
autowire: true
Trendio\DelivBundle\TrendioUserProvider: ~
Trendio\DelivBundle\Services\TrendioRest:
arguments: [%trendio.rest.backend_ip%]