How to load module's view from its controller with a layout?

edited June 2014 in Share
I've created a module at this location: fuel/modules/module-name/
The module-name directory contains these directories: views, models and controllers
I am trying to load a module view from a controller using this code:
$this->load->module_library(
'fuel_page',
array('location' => '/modules/module-name/views/myClass')
);
$this->fuel_page->render();
But I get this error:

Unable to load the requested class: myClass

I also tried this:
$this->load->view('/modules/module-name/views/myClass');
And got this error:

Unable to locate the file: modules/module-name/views/myClass.php

How can I load myClass.php file from controller? I need to render this view with the main layout (along with header and footer). How can I tell fuel to load this view using the main layout?

Comments

  • edited 12:10PM
    What version of FUEL are you using (you can echo the FUEL_VERSION constant to find out)? The reason I ask is because the syntax above is older.

    $vars = array(); $this->fuel->pages->render('mylocation', $vars, array('view_module' => 'my_module'));
  • edited June 2014
    I am using version 1.0.6 which should be the latest. Your approach does not raise any error, but I just get an empty page:
    $vars = array();
    echo FUEL_VERSION; // this is written to the output
    $this->fuel->pages->render('registeration', $vars, array('view_module' => 'registeration')); // nothing happens
    Here is the hierarchy of files in the module I intend to use:

    fuel/application
    fuel/codeigniter
    fuel/modules/registeration

    fuel/modules/registeration/controllers
    fuel/modules/registeration/models
    fuel/modules/registeration/views

    fuel/modules/registeration/controllers/registeration.php
    fuel/modules/registeration/models/registerations_model.php
    fuel/modules/registeration/views/registeration.php

    The content of "controllers/registeration.php":

    <?php
    class Registeration extends CI_Controller
    {
    public function add()
    {
    $vars = array();
    echo FUEL_VERSION;
    $this->fuel->pages->render('registeration', $vars, array('view_module' => 'registeration'));
    }
    }
    The content of "views/registeration.php" is:

    <?php echo 'registeration';?>
    What am I doing wrong here?
  • edited 12:10PM
    Is there anything I am missing in my code?
  • edited 12:10PM
    What is the URI location relative to your web folder that is causing the problem? You may also want to add "render_mode" => "views" next to the "view_module" => "registeration".
Sign In or Register to comment.