Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Load view from Module
  • Hello everybody,

    I am beginning write a Module, i want all view which have relative with that module will be store at App/Module/[name_module]/view. How can i load those files from module controller and assign it to template 

    Welfare and Regards
  • You mean: how can I load a module view from a controller outside the module?

    The short answer: make sure the module is loaded, and then hardcoded load the view from the module.

    \Module::load("[name_module]");
    $view = \View::forge("[name_module]::[view_name]");

    Note that is creates a hard-coupling with your module, and is considered bad practice. It's better to execute an HMVC request to a controller in the module, and have that controller return the View.
  • The Module is loaded .

    all view files of module example will be stored at this path app/modules/example/view/.

    So i want to know could i load the file at this app/modules/example/view/index.php from
      app/modules/example/controller/index.php

    and how to do that . ^^

    Sorry about my not good english to make a not clear question.


  • HarroHarro
    Accepted Answer
    From a controller inside the module? Exactly the same as from every other controller:

    $view = \View::forge('index');

    FuelPHP is context aware, it knows you're executing a module controller, so it knows to look in the module for views, config files, lang files, etc.

    p.s. it's app/modules/example/views/index.php, so "views" not "view". If you have made this mistake, no views will be loaded either...
  • Thank you very much.

Howdy, Stranger!

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

In this Discussion