More documentation for Models in namespace

Hi, just checking the "Working with models" section of the documentaiton and i think a fewer examples about how to use namespaced models would be welcome. Maybe it is located everywhere ? But didnt find it.

Thanks dev team !



82.3k

Just define the class into a namespace:

namespace Store\Models;

class Robots extends Phalcon\Mvc\Model
{

}

If you have relationships they must include the namespace too:

namespace Store\Models;

class Robots extends Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->hasMany('id', 'Store\Models\Parts', 'robots_id', array(
            'alias' => 'parts'
        ));
    }   
}

In PHQL you must write the statements including namespaces:

$phql = 'SELECT r.* FROM Store\Models\Robots r JOIN Store\Models\Parts p';

You must use an autoloader that supports a namespace strategy: http://docs.phalconphp.com/en/latest/reference/loader.html#registering-namespaces

Thanks for that,

moreover as i said here in the last reply : http://forum.phalconphp.com/discussion/434/namespaces-in-model-generation and here in the comment : https://github.com/phalcon/phalcon-devtools/commit/547d35af4940375e891911b8b0283779c497664d#commitcomment-3446388

I think a little mistake was done in the dev tools. Just have a look.