Location of model classes

Hi all,

In the official documentation of Models:

A model is a class that extends from Phalcon\Mvc\Model. It must be placed in the models directory.

Why should it be in "models" directory? Can this be overridden?

I have a structure like:

\MyAppNamespace\User\Model.php \MyAppNamespace\ObjectA\Model.php \MyAppNamespace\ObjectB\Model.php

I don't group my application models together.

Besides, Phalcon\Mvc\Model\Manager should not even concern itself with the location of classes. It's a task of autoloader.

Any thoughts?

Thanks, Temuri

It's just convention. You are free to load your models almost everywhere you want, but in this case you must add (register) this places with Phalcon\Loader()



31.5k

Thanks, Vladimir.

So, to be able to load my models in the case above, I should explicitely define three namespaces for the loader:

$loader->registerNamespaces([ 'MyAppNamespace\User' => APPDIR . '/MyAppNamespace/User', 'MyAppNamespace\ObjectA' => APPDIR . '/MyAppNamespace/ObjectA', 'MyAppNamespace\ObjectB' => APP_DIR . '/MyAppNamespace/ObjectB', ]);

Did I understand you correctly?

yep, it should work