4

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. Commented Aug 6, 2015 at 5:43

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.