Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Working with modules
  • Hi, I am new to fuelphp and basically the whole namespace thing.
    Reading the docs, it seems creating modules is fairly easing. I somehow seem to mis something I believe. I created a module called 'admin' because I want to seperate all admin activities from the rest of the application.
    In admin/classes/controller/ there is a controller class called admin.php:
    <?php
    namespace Admin;
    
    class Controller_Admin extends \Controller
    {
    
     /**
      * The basic welcome message
      * 
      * @access  public
      * @return  Response
      */
     public function action_index()
     {
      return \Response::forge(\ViewModel::forge('welcome/hello'));
     }
    
    }
    

    Upon visiting /admin/index I get the message: OutOfBoundsException [ Error ]: ViewModel "View_Welcome_hello" could not be found. Now I understand it means it can not find the viewModel but what would I need to do to make sure the module can find the view?
    I have read the docs but can't find what I am doing wrong
  • If you want to return a viewmodel, you have to make the viewmodel class, in modules/admin/classes/view/welcome/hello.php if you use the name 'welcome/hello'. See http://docs.fuelphp.com/general/viewmodels.html which describes what a viewmodel is and how it works. If you want to return a view, don't forge a viewmodel, forge a view. Modules are like mini-apps, they are self-contained, and have their own classes and views folders, like your app. If you load a view from a module controller, it will look in the views folder of the module to load the view. If not found, it will check your app/views folder to see if there is a global view defined with the requested name.
  • Harro Verton wrote on Wednesday 13th of June 2012:
    If you want to return a viewmodel, you have to make the viewmodel class, in modules/admin/classes/view/welcome/hello.php if you use the name 'welcome/hello'. See http://docs.fuelphp.com/general/viewmodels.html which describes what a viewmodel is and how it works. If you want to return a view, don't forge a viewmodel, forge a view. Modules are like mini-apps, they are self-contained, and have their own classes and views folders, like your app. If you load a view from a module controller, it will look in the views folder of the module to load the view. If not found, it will check your app/views folder to see if there is a global view defined with the requested name.

    Thanks for your response, yes I know that the view model has to be created and I have. The location of my view model is exactly : modules\admin\classes\view\welcome\hello.php

Howdy, Stranger!

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

In this Discussion