Namespace not found? Symfony2
Newbie problem here, I created a Bundle named MyServices with a MyBundle Sub-folder,
I created a service named myAWServ, but when I call $this->get('myAWS')->methodCall()
I get the following error:
CRITICAL - Fatal Error: Class 'MyServices \ MyBundle \ myAWS \ myAWS' not found CRITICAL - Unused PHP Symfony \ Component \ Debug \ Exception \ ClassNotFoundException: "Trying to load class" myAWS "from namespace" MyServices \ MyBundle \ myAWS ". Did you forget to "use" for a different namespace? " to / home / sergio / Desktop / hello _symfony_heroku / app / cache / dev / appDevDebugProjectContainer.php line 1755
I have looked through all the files a hundred times and cannot find the problem with the files:
<?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;
}
}
Root file generated with 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
{
}
and services.yml
parameters:
myAWS.class: MyServices\MyBundle\myAWS\myAWS
services:
myAWSer:
class: "%myAWS.class%"
arguments: [teste]
I have new MyServices \ MyBundle \ MyServicesMyBundle () loading in AppKernel,
I am currently making a simple call
<?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));
}
}
I have also tried clearing the cache. Sorry for the long post and thank you in advance.
source to share
The problem is here:
// File Location : MyServices/MyBundle/Controller/myAWS.php
namespace MyServices\MyBundle\myAWS;
Your file path MyServices/MyBundle/Controller/myAWS.php
, but you must follow your namespace, so the correct path must be MyServices/MyBundle/myAWS/myAWS.php
. You should also check psr-4 for autoloading .
source to share