Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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");


9.3k

OK, Thanks a lot!

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

```php $di->set( 'modelsManager', function () { $modelsManager = new ModelsManager(); $modelsManager->registerNamespaceAlias( 'm', 'ABACom\Models\Metas' ); return $modelsManager; } ); ```

```php $this->modelsManager->executeQuery("SELECT * FROM m:Metas"); ```