这里有新手问题,我用Sub文件夹MyBundle创建了一个名为MyServices的Bundle,
我've created a Service named myAWServ but as I'我正在调用 $this->get('myAWS')->methodCall()
我收到以下错误:
CRITICAL - 致命错误:类'MyServices \ MyBundle \ myAWS \ myAWS'未找到CRITICAL - 未捕获PHP异常Symfony \ Component \ Debug \ Exception \ ClassNotFoundException:“尝试从命名空间”MyServices \ MyBundle \ myAWS“加载类”myAWS“你忘记了另一个命名空间的“use”语句吗?“在/home/sergio/Desktop/hello_symfony_heroku/app/cache/dev/appDevDebugProjectContainer.php第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创建的Root文件(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中加载了新的MyServices \ 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));
}
}
我也试过清除缓存 . 对不起,很长的帖子,谢谢你提前 .
1 回答
问题出在这里:
您的文件路径是
MyServices/MyBundle/Controller/myAWS.php
但您必须遵循您的命名空间,因此正确的路径应该是MyServices/MyBundle/myAWS/myAWS.php
. 您还应该查看psr-4 specifications for autoloading .