Problems loading view from module (SOLVED)

edited September 2011 in Modules
Ok so I'm trying to expand on this topic:
http://www.getfuelcms.com/forums/discussion/329/need-help-with-making-custom-module-front-end-views-advanced-module/p1
and this topic is very similar to my issue:
http://www.getfuelcms.com/forums/discussion/comment/1820/#Comment_1820

remark: I had to comment out +FollowSymlinks in the .htaccess file.

Edit: when I add a view file to application/views it works.

modules/test/controllers/test.php:

<?php class Test extends CI_Controller { public $view_location = 'test'; function __construct() { parent::__construct(); } function contact() { //echo "test"; -> works when uncommented // set your variables $vars = array( 'page_title' => 'Contact : My Website', 'data' => 'if all goes well this should be visible' ); //... form code goes here // load the fuel_page library class and pass it the view file you want to load $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'test/contact')); $this->fuel_page->add_variables($vars); $this->fuel_page->render(); } }

modules/test/views/test.php:

<?php print $data; ?> <p>more text</p>

$config['fuel_mode'] = 'auto';

Still get the error 404, I've tried everything in several posts I found on this forum.
Thanks for reading.

Comments

  • edited 10:09PM
    Try adding:

    'render_mode'=>'cms'

    to your module_library array:

    $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'test/contact', 'render_mode' => 'cms'))
  • edited 10:09PM
    Unfortunately that does not help.
    Does anyone have a working example of an easy-to-understand advanced module? The blog is way too advanced and furthermore makes no use of module_library() in the way we need to to load a view.
  • edited 10:09PM
    TEST 2. View is loaded from application/views, not from modules folder.
    When I remove the membership.php file from this location I get a blank page.

    <?php class Membership extends CI_Controller { public $view_location = 'membership'; // although here, view is still loaded from main application/views function __construct() { parent::__construct(); $this->config->load('membership', 'membership'); } function index() { // set your variables $vars = array('page_title' => 'Membership'); // load the fuel_page library class and pass it the view file you want to load $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'membership'/*, 'views_path' => 'membership'*/)); $this->fuel_page->add_variables($vars); $this->fuel_page->render(); //$this->load->view('membership', $vars); // loads view from correct module folder } }

    When I add 'views_path' => 'membership' I get a blank page.
    Adding 'render_mode'=>'cms' (or 'views') does not change anything.

    So in fact my only issue to solve is to get the correct views path loaded. I hope.
  • edited 10:09PM
    The view_location value in the controller is intended for backend module controllers. This controller appears to be something you want to render on the front end. The "Opt-in" controller method is only really intended for those files in the application views folder directory at this time.

    If you are simply just wanting to load that view you can use:
    $this->load->module_view('membership', 'my_membership_view', $vars);

    If you have content on that page that you want to include inline editing with, you can do something like the following (grabbed from Blog_base_controller):
    $output = $this->load->module_view('membership', 'my_membership_view', $vars, TRUE); $this->load->module_library(FUEL_FOLDER, 'fuel_page'); $this->fuel_page->initialize(); $output = $this->fuel_page->fuelify($output); $this->output->set_output($output);
  • edited 10:09PM
    Thanks for your reply.

    I should have included what I want to accomplish. I'd like to use the layout files from MY_fuel_modules and have my module view inserted into it (in stead of loading the one in fuel/application/views). Should I call them with the $vars array (and how?) or should I create a separate _layout folder for my module?
  • edited 10:09PM
    Is this for something in the admin or for the front end?
  • edited September 2011
    front-end
    I'd like to use the MX way of working with modules per site section so that in case I need to move them to another project I have to copy just one folder.
    I'm loving this CMS btw, just here and there it's fairly different from anything I've done before in CI.
    I'm getting results!
  • edited 10:09PM
    Since you are operating outside of the application folder, the opt-in controller method won't work as easily. However, the blog module sounds like it may have a solution similar to what you are looking for. In particular the _render method in the library class fuel/modules/blog/libraries/Blog_base_controller.php

    In that method, it grabs any variables associated with the current uri path with:
    $_vars = $this->fuel_pagevars->retrieve(uri_path());
    It then loads the content of the page into a "body" variable, which then gets loaded into the layout. Passing the output to the "fuelify()" method at the end will convert any inline editing code
  • edited September 2011
    I've been trying but without success.

    $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'membership/register'));
    How can I get the location to load my module view in stead of the view in fuel/application/views? Sorry for all the trouble.

    EDIT:
    made some progress:
    $vars['body'] = $this->load->module_view(MEMBERSHIP_FOLDER, 'themes/default/test', $vars, TRUE); $view = $this->load->view('_layouts/main', $vars); $this->load->module_library(FUEL_FOLDER, 'fuel_page', $view); $this->fuel_page->add_variables($vars); $this->fuel_page->render();
    But now I get the FUEL_MARKER placeholders where global variables should be. I feel like I'm close and want that sigar :). I'm merging the $_vars with my existing $vars array as you suggest but must be doing something wrong.
  • edited 10:09PM
    Are there any PHP errors in the page (perhaps do a view source and search for any errors)? If the execution of the page is exited because of an error, those markers will show up.
  • edited September 2011
    No errors.
    the global vars are loaded though so the markers being there is not a very big problem for me.
    Is there a way to make fuel_var() available? I tried loading the fuel_helper in my membership controller but to no avail.
    Thanks

    require_once(FUEL_PATH.'helpers/fuel_helper.php'); could it work? trying in different locations.
  • edited 10:09PM
    Fuel helper should be autoloaded already (it's in the autoload.php file in the config folder). Did you get an error with fuel_var or did something simply not appear? The markers should be stripped out during the rendering process but there seems to be an issue with that. What if you try something like this
    $vars['body'] = $this->load->module_view(MEMBERSHIP_FOLDER, 'themes/default/test', $vars, TRUE); $output = $this->load->view('_layouts/main', $vars, TRUE); $this->load->module_library(FUEL_FOLDER, 'fuel_page'); $this->fuel_page->initialize(); $output = $this->fuel_page->fuelify($output);
  • edited September 2011
    The only issue left is the markers. No errors, fuel_var does what it should, I was on a wrong path there for a moment.

    As soon as I put$output = $this->load->view('_layouts/main', $vars, TRUE);to TRUE it returns a blank page.

    Unless I add
    print $output;at the bottom. Then everything works as it should. Markers are gone. Return doesn't work, same blank page.

    Also, whether I add
    $this->load->module_library(FUEL_FOLDER, 'fuel_page'); $this->fuel_page->initialize(); or not, no difference.

    Is there a time when markers should be displayed? Whether I log in or not, don't see them.

    Edit: using$this->output->set_output($output); Works and is much better then using print, I think this is solved? In the meantime I got to know the code a whole lot better!
    Thanks for your persisent assitance!!
  • edited October 2011
    Glad you were able to figure it out!
Sign In or Register to comment.