How I can alias namespace for model in PHQL?

I have a model class: App\Frontend\Models\Users, when I use PHQL, the statement is too long! I

$phql = 'select  from App\Frontend\Models\Users  as u';

Then I found a method from API Documnet:

modelsManager->registerNamespaceAlias( $alias , $namespece);

but can someone tell me how to use it? I can't find any information about it from the document!

I have tried the follow statements, all of them trigger class not found error:

$phql = 'select  from ns\Users  as u';
$phql = 'select  from users  as u';

here is an example of Alias in Phql:

        $foo = $this->modelsManager->createBuilder()
            ->columns('m.*, As gate_name')
            ->from(['m' => 'App\Model\Merchants'])
            ->join('App\Model\Gateways', 'm.fk_gateway_id =', 'g')
            ->where('m.fk_member_id = :memberID:', ['memberID' => $this->auth->getIdentity()['id']]);

check this link:

edited Mar '15

No. I's not my need,thanks. In your example, every Builder Instance must create with a alias part. So , 10 Builders need 10 times


I think it's so long so bored.

Why not register a model class alias just once time then use it in anywhere?

here is an example of Alias in Phql:

```php $foo = $this->modelsManager->createBuilder() ->columns('m.*, As gatename') ->from(['m' => 'App\Model\Merchants']) ->join('App\Model\Gateways', 'm.fkgatewayid =', 'g') ->orderBy('') ->where('m.fkmember_id = :memberID:', ['memberID' => $this->auth->getIdentity()['id']]); ```

check this link:


In fact, I want to know the function of modelsManager->registerNamespaceAlias( $alias , $namespece);

edited Mar '15

I have the same question.

// wrong: throws exception :
// Fatal error: Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'Model 'PrintTask' could not be loaded' in ...
$phql  = "SELECT AS id FROM PrintTask";
$rows = $this->modelsManager->executeQuery($phql);

// right: but not elegant 
$phql  = "SELECT \Apps\Prints\Model\ AS id FROM \Apps\Prints\Model\PrintTask";    
$rows = $this->modelsManager->executeQuery($phql);

the problem is $this->modelsManager->registerNamespaceAlias didn't work! need help @phalcon

I don't know but using namespace in Phalcon 2.0 didn't work now :(

edited May '15


$phql  = "SELECT AS id FROM \Apps\Prints\Model\PrintTask AS p";


@Andres Gutierrez