Hi there, I am having trouble with View::forge and taks. I have a task that calls a method in a model to send emails. In that model I take the data to send it to a view to create the HTML that will form the body of the email $EmailBody = \View::forge(alerts\emails\listing_alert',array('listings'=>$Listings));
When I run the task from the command prompt using oil refine, it gives me an error that the view could not be found.
So far I have figured out that the path is obviously wrong in reference to oil but when I "call" that model using the browser it works fine.
The question is, how/where/what do I set the path so that oil will recognize or find the view.
I have tried using APPPATH and DOCROOT but those did not make any difference.
The view is a module view, everything (the method and the view) is in one module. The task calls the method directly but when i test it in a browser it works and the view is found. But when I test it in the browser I call the controller that calls the method in the model
Does oil use the app views path instead of the module views? If so do I just set the view forge path to point to the app views instead of the default module view?
Thank you for the help Harro, It is fixed now. I moved the view to the app views folder and tested it with oil refine and it works without any problems.
The problem was probably that the module "view" wasn't loaded, so the View loader doesn't have a path to it it can search. When you call a controller in a module, the module is autoloaded.
In a task, you need to use
\Module::load('vlew');
to make the views in that module loadable.
Was the task in ./app/tasks, or in ./app/modules/view/tasks ?
The task is in ./app/tasks With the \Module::load('vlew'); would the view be the module or the actual core View.
The module is loaded in the task since the model method is called in that module. That is why I could not figure out why the view wont load seeing as the module is loaded.
The alerts in the path is a folder. so the folder structure of the view is ./app/modules/alerts/views/alerts/emails/listing_alert.php
When I run it in the browser the action_index of the Alerts controller has Model_Alerts::processAlerts(); Tee browser call works. So doing it through the controller works fine without any problems.
In the task I load the module and call the same method in the model:
That is when it does not find the ./app/modules/alerts/views/alerts/emails/listing_alert.php view. But when I move that view to ./app/views/alerts/emails/listing_alert.php there is no problem.
This means that if you load the module view in a module controller, or if you load the view from a module task, it works, because you are in "module context".
It doesn't work from an app controller, from another module controller (wrong context), from an app task, or from a task in another module.
In other words, if you want to use module views in a test, this task must be in the same module. If not, you have to explicitly indicate you want to load the view from the module, by using the "module::" prefix to the view name.
I had a feeling that the issue could be related to the fact that when I run it in a browser the context is loaded for that module but when I do it from the task that is set in the main application it does not have that reference.
I did resolve the issue though by putting the view in the app/views folder instead of the module/views folder. Seeing as this specific method will only be called by the task it does not require the view in the modules/view folder so there is no duplication of the view itself.