Hi all,
Not sure if this is a bug/what a suitable workaround is but, bear with my while I try to explain this:
If I have a controller, in module called Pages. Everything in the Pages module is in the Pages namespace.
I have a ViewModel called Menu which is in the Pages module. There is a view in the Pages module in the directory common/menu.php which the ViewModel uses.
The Pages controller calls the ViewModel correctly and the common/menu.php shows as expected.
I've now overloaded the ViewModel in APPPATH/classes/view and it gets called correctly. I then create a view in APPPATH/views/common/menu.php.
Crux
When I call the ViewModel in the Pages controller it shows the view in the Pages module but when I call the same ViewModel anywhere outside of the Controller, it shows the view in APPPATH/views.
Any ideas of ways around this?
Rob
It all depends on your definition of "outside".
When you forge a Viewmodel object, it will forge the corresponding View object for you. The view file is located using Finder::search(), which is a context aware search.
Part of the context is the request environment. If the request has loaded a module controller, that module is autoloaded by the routing engine, and the module path is part of the context, and has precendence over other paths defined (usually only APPPATH and PKGPATHs).
No matter where the View::forge() is located in your code, within that request the module path will always be part of the context and will be searched first. So it shouldn't matter that you call a global Viewmodel, the module view file should be found first and loaded.
Consequently, if you do the same call in a different content (for example an other module's controller, or an app controller, the module path isn't part of the context, and the finder will not look in your module's views folder.