0

Class 'AdoDoctrineModel' not found in C:\wamp\www\test\src\Ado\FrontendBundle\Helper\AdoFactory.php on line 22

<?php

namespace Ado\FrontendBundle\Helper;

use AdoDoctrineModel;
use AdoApiModel;

class AdoFactory {
    protected $adapter; 

    public function __construct($container) {
        $this->adapter = $container->getParameter('adapter'); 
    }

    public function getModel()  {

        switch($this->adapter)
        {
            case 'API':
            case 'Doctrine': 
                $class = 'Ado' . $this->adapter. 'Model'; 
                return new $class;
            break;
            default: throw new Exception("unsupported format: " . $type);
        }
    }
}

?>

And AdoDoctrineModel.php

namespace Ado\FrontendBundle\Helper;

class AdoDoctrineModel {

    public function __construct() {

    }

}

I have tried changing use path in AdoFactory to full path, also adding "use {...} as AdoDoctrineModel" Tried \new AdoDoctrineModel

Any help would be great!

1
  • Have you tried use Ado\FrontendBundle\Helper\AdoDoctrineModel;? Commented Feb 14, 2013 at 14:45

2 Answers 2

1

remove that code :

use AdoDoctrineModel;
use AdoApiModel;

and everything should work fine. you need to refresh your understanding of how php namespaces work, check the doc on namespaces.

what you are currently telling your app is fetch a non existent \AdoDoctrineModel class and \AdoApiModel instead of of \Ado\FrontendBundle\Helper\AdoDoctrineModel and \Ado\FrontendBundle\Helper\AdoApiModel classes.

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

Comments

1

I assume your are using Composer (Symfony 2.1.x). Your code seems fine to me, I would check composer.json file for this section:

"autoload": {
    "psr-0": {
        "": "src/"
    }
}

And then issue:

composer dump-autoload

Of course file AdoDoctrineModel.php should be placed inside src/Ado/FrontendBundle/Helper folder. There is no need for use statement as both classes are in the same namespace.

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.