4
votes

Newbie problem here, I've created a Bundle named MyServices with Sub folder MyBundle,

I've created a Service named myAWServ but as I'm calling $this->get('myAWS')->methodCall() I'm getting the following error :

CRITICAL - Fatal Error: Class 'MyServices\MyBundle\myAWS\myAWS' not found CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted to load class "myAWS" from namespace "MyServices\MyBundle\myAWS". Did you forget a "use" statement for another namespace?" at /home/sergio/Desktop/hello_symfony_heroku/app/cache/dev/appDevDebugProjectContainer.php line 1755

I've reviewed all files a hundred times and can't find the problem the files are as it follow:

<?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;
    }
}

The Root file created with the 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 the services.yml

parameters:
    myAWS.class: MyServices\MyBundle\myAWS\myAWS

services:
    myAWSer:
        class: "%myAWS.class%"
        arguments: [teste]

I've got it loading in the AppKernel new MyServices\MyBundle\MyServicesMyBundle(),

Currently im doing 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've also tried clearing the cache. Sorry for the long post, and thank you in advance.

1
There is a Controller fraction in the path, but there is no such in the namespace. There is also myAWS\myAWS --- it's 2 myAWS while in the path it's only one myAWS entry. - zerkms

1 Answers

6
votes

The problem is here:

// File Location : MyServices/MyBundle/Controller/myAWS.php
namespace MyServices\MyBundle\myAWS;

Your file's path is MyServices/MyBundle/Controller/myAWS.php but you must follow your namespace, so the correct path should be MyServices/MyBundle/myAWS/myAWS.php. You should also check out the psr-4 specifications for autoloading.