0

I have a Symfony 2.2 project with just one app called "Xedef". Inside that app folder, I've created a Model directory with some classes in it. I was hoping I could just define a namespace for that classes as declaring the namespace as:

namespace Xedef\Model;

class MyClass
{
    // ...
}

And then use them from, let's say, my controler just by "using" that namespaces as:

use Xedef\Model\MyClass;

class HomeController extends Controller
{
    public function welcomeAction()
    {
        $myObj = new MyClass();
    }
}

But I had no luck. This results in the following error:

FatalErrorException: Error: Class 'Xedef\Model\MyClass' not found in /gitRepo/XedefApp/src/Xedef/MainBundle/Controller/HomeController.php

Oddly, I did this same thing in Sf 2.1 and I hadn't any troubles. Did something changed in 2.2?

j0k
  • 22,600
  • 28
  • 79
  • 90
  • 1
    Where is the model class? In the `app` directory?... it is autoloaded only if it's under the `src` directory. – 1ed Apr 28 '13 at 00:04

1 Answers1

1

If you want to autoload classes, you should place them in the src or vendor directory. You can also edit the composer.json file if you want to autoload the classes from another directory:

{
    ...
    "autoload": {
        "psr-0": {
            ...
            "Xedef": "path/to/Xedef"
        }
    }
}
Wouter J
  • 41,455
  • 15
  • 107
  • 112