We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to appoint the default NAMESPACE of PHQL?

To excute the following code, it says Model Metas can not find.

$this->modelsManager->executeQuery("SELECT * from Metas");

but if I specify a namespace, it works:

$this->modelsManager->executeQuery("SELECT * from ABACom\Models\Metas");

How to appoint the default namespace to the PHQL?



879
Accepted
answer
edited Nov '15

I'm afraid there's no way to set default namespace but you can use namespace aliases:

$di->set(
    'modelsManager', 
    function () {
        $modelsManager = new ModelsManager();
        $modelsManager->registerNamespaceAlias(
            'm',
             'ABACom\Models\Metas'
         );
        return $modelsManager;
    }
);
$this->modelsManager->executeQuery("SELECT * FROM m:Metas");


31.3k

OK, Thanks a lot!

I'm afraid there's no way to set default namespace but you can use namespace aliases:

$di->set(
   'modelsManager', 
   function () {
       $modelsManager = new ModelsManager();
       $modelsManager->registerNamespaceAlias(
           'm',
            'ABACom\Models\Metas'
        );
       return $modelsManager;
   }
);
$this->modelsManager->executeQuery("SELECT * FROM m:Metas");