新手问题在这里,我已经创建了一个名为MyServices的Bundle,子文件夹MyBundle,
我已经创建了一个名为myAWServ的服务,但当我调用$this->get('myAWS')->methodCall()
时,我得到以下错误:
临界-致命错误:类"MyServices'MyBundle'myAWS'myAWS"不存在found CRITICAL -未捕获的PHP异常Symfony '组件'调试' ' ClassNotFoundException异常:"未遂从命名空间"MyServices'MyBundle'myAWS"中加载类"myAWS"。做了您忘记了另一个名称空间的"use"语句缓存/dev/appDevDebugProjectContainer.php/home/sergio/Desktop/hello_symfony_heroku/app/第1755行
我把所有的文件都看了一百遍,还是找不到问题,文件如下:
<?php
//File Location : MyServices/MyBundle/Controller/myAWS.php
namespace MyServices'MyBundle'myAWS;
class myAWS
{
public function __construct($greeting)
{
$this->greeting = $greeting;
}
public function greet($name)
{
return $this->greeting . ' ' . $name;
}
}
用bundle创建的根文件(php app/console generate:bundle)
//Filesource : MyServices/MyBundle/MyServicesMyBundle.php
<?php
namespace MyServices'MyBundle;
use Symfony'Component'HttpKernel'Bundle'Bundle;
class MyServicesMyBundle extends Bundle
{
}
和services.yml
parameters:
myAWS.class: MyServices'MyBundle'myAWS'myAWS
services:
myAWSer:
class: "%myAWS.class%"
arguments: [teste]
我已经在AppKernel中加载了它新myservice ' MyBundle ' MyServicesMyBundle ()
当前我正在做一个简单的调用
<?php
namespace MyServices'MyBundle'Controller;
use Symfony'Bundle'FrameworkBundle'Controller'Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
die($this->get('myAWSer')->greet($name));
}
}
我也试过清理缓存。很抱歉写了这么长时间,提前感谢。
问题就在这里:
// File Location : MyServices/MyBundle/Controller/myAWS.php
namespace MyServices'MyBundle'myAWS;
你的文件的路径是MyServices/MyBundle/Controller/myAWS.php
,但是你必须遵循你的命名空间,所以正确的路径应该是MyServices/MyBundle/myAWS/myAWS.php
。您还应该查看psr-4的自动加载规范。