Solved thread


Phalcon\Mvc\Model\Manager with namespace model class


I try to use the Phalcon\Mvc\Model\Manager in this way :

        $query = $this->modelsManager->createQuery(
                    ifnull(tv.Value, '') as Value
                FROM Translation t
                left join TranslationValue tv on tv.TranslationID = t.ID
                left join Locale l on l.ID = tv.LocaleID
                where LocaleID = :id: or
                (tv.Value is null or l.ID is null)");

        $translation = $query->execute(array(

            'id' => $locale->getFirst()->ID

When the execute method is execute, I'm getting this message :

Model 'Translation' could not be loaded.

The model class Translation is in a namespace => namespace NearbyMe\Backend\Models;

Does the Phalcon\Mvc\Model\Manager can introspect a class within a namespace ?

If a use $Transaction::find() there is no problem, but I don't have my children the way I need them.

edited Oct '14


I've never used the Model Manager yet. But I think you need to add the namespace like so...


$query = $this->modelsManager->createQuery(/** ... previous code ...*/ FROM My\Namespace\Translation t left join TranslationValue tv /** ... */);


That did the trick.

Thank you !

On side note. This is not Phalcon related. It's how namespaces works in PHP. From PHP Docs: "Importing is performed at compile-time, and so does not affect dynamic class, function or constant names." so you can't write:

use NS\ClassName;

$a = 'ClassName';
$b = new $a();

You must write

use NS\ClassName;

$a = 'NS\ClassName';
$b = new $a();