Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Task View Forge Issue
  • 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.

    Thank you.
  • HarroHarro
    Accepted Answer
    Is that an app view, or a module view? When you do the same in a controller, it can find it?
  • 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?

    Thanks.
  • 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.

    Thank you!
    Have a great day.
  • 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.

    Thank you.
  • Ok, so:
    - task in app/tasks
    - task already loaded the module
    - view in the module
    ?

    If so, you've found a bug that I'll have to look at.
  • 1- Correct: Taks is in app/tasks
    2- Correct: Module is loaded in the task
    3- Correct: The view is in the module

    Thank you.
  • And you load the view in your controller how? To load from a(nother) module, you need to use

    $EmailBody = \View::forge(alerts::emails\listing_alert',array('listings'=>$Listings));

    I don't think your original View statement worked in a controller too, it wouldn't be able to find a view path starting with 'alerts'. 
  • 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:

    \Module::load('Alerts');       
    Model_Alerts::processAlerts();

    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.

    Thank you.
  • Ah, ok, "alerts/emails/listing_alert.php" is the full view path, I was confused with the name of the module.

    Clear, back to debugging then.
  • Ok, the situation is the following:

    For search paths, Fuel follows this list:
    - manual added paths
    - when in a module context, module paths
    - app paths
    - package paths
    - framework paths

    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.
  • Thank you Harro,

    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.

    Thank you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion