When migrating an app from 3.4.4 to 4.0.0-rc1 I am getting a fatal error during the bootstrap relating to model namespace aliases:
Fatal error: Uncaught Error: Call to undefined method Phalcon\Mvc\Model\Manager::registerNamespaceAlias()
Steps to reproduce the behavior:
use Phalcon\Mvc\Model\Manager as ModelManager;
$manager = new ModelManager;
$manager->registerNamespaceAlas('Core', 'Modules\Core\Models');
Expected behavior
To be able to use the registered alias in Phalcon\Mvc\Model\Query\Builder joins / selects etc e.g. instead of referencing \Modules\Core\Models\Users you could use Core:Users instead.
I'm not sure if this has been removed in 4.x, but more complex multi-module MVC applications that made use of this feature from 3.x will require a fair bit of refactoring.
The changlog for 4.0.x mentions this method as part of an interface - Phalcon\Mvc\Model\ManagerInterface but I cannot see any other references.
Details
Additional context
Add any other context about the problem here.
Thank you for trying out the RC1!
This method has been removed in Alpha.5 (see changelog last line). I assume this should be removed from the interface as well but will check with @niden We should mention this more clear in the upgrade docs and changelog. Thnx for reporting.
Thanks @ruudboon - excited to be using 4 RC1 and looking forward to the stable release! Are there any workarounds that can be suggested for this? I do make use of this a fair bit in my code. Was it removed for any particular reason?
Yea, im not sure too why it was removed exactly, alternative is just ClassName::class and just always set alias in queries.
@richmilns need to check the details on this change. Will let you know.
You could always extend the Manager and add that functionality yourself. But let's figure out the reason first.
So to add some context to all of this, I was the one who removed this functionality in https://github.com/phalcon/cphalcon/pull/14028. The idea behind it was to reduce the complexity of Phalcon's codebase and to simplify things for developers by removing multiple ways to perform the same task. FQDNs (like Album::class) are far superior as it makes it trivial to know where the model class is and to refactor/rename it should you wish. Namespace aliases were essentially just a crude way of replicating PHP namespaces which is unnecessary considering its easy enough using FQDNs anyway. Hope this helps.
@SidRoberts Thnx for explaining. I will create a pull to update the changelog. Method was already removed form interface (Changelog mention was wrong).
Changelog is fixed in 4.0.x branch. Docs are updated as well.
OK Thanks, that does make sense @SidRoberts. Just so I'm clear, are you saying that instead of this:
$builder->leftJoin('Agencies:Agencies', 'Agencies.id = JobsAgencies.agency_id', 'Agencies');
You would do something like this instead?
// top of your class
use Modules\Agencies\Models\Agencies;
// lower down your code
$builder->leftJoin(Agencies::class, 'Agencies.id = JobsAgencies.agency_id', 'Agencies');
@richmilns Yes exactly that.
Most helpful comment
So to add some context to all of this, I was the one who removed this functionality in https://github.com/phalcon/cphalcon/pull/14028. The idea behind it was to reduce the complexity of Phalcon's codebase and to simplify things for developers by removing multiple ways to perform the same task. FQDNs (like
Album::class) are far superior as it makes it trivial to know where the model class is and to refactor/rename it should you wish. Namespace aliases were essentially just a crude way of replicating PHP namespaces which is unnecessary considering its easy enough using FQDNs anyway. Hope this helps.