这里有新手问题,我用Sub文件夹MyBundle创建了一个名为MyServices的Bundle,
我创建了一个名为myAWServ的服务但是因为我正在调用$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;
}
}
Run Code Online (Sandbox Code Playgroud)
使用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
{
}
Run Code Online (Sandbox Code Playgroud)
和services.yml
parameters:
myAWS.class: MyServices\MyBundle\myAWS\myAWS
services:
myAWSer:
class: "%myAWS.class%"
arguments: [teste]
Run Code Online (Sandbox Code Playgroud)
我已经在AppKernel中加载了新的MyServices\MyBundle\MyServicesMyBundle(),
目前我正在做一个简单的电话
<?php
namespace MyServices\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller …Run Code Online (Sandbox Code Playgroud)