Advanced Controller views v 1.0

edited February 2013 in Share
So, here we go again :)

What I have is an advanced module.
Works awesome through the CMS.

Now, I need to implement the front-end portion of it. Right now all I want to do is have the module's view file output some form information, but to start I just want it to output $vars['body'] = 'test'; to the view file in /modules/membership/views/membership.php

I can do that, no problem.

So, my issue comes with implementing the sites view files: /application/views/_layouts/main.php which includes /application/views/_blocks/header.php and footer.php

I can do that too.

What happens when I do that though is my Site Variables from the CMS don't transfer through, and neither do css($css) or js($js).

Here's my controller for my membership module controller:
<?php class Membership extends CI_Controller { public $view_location = 'membership'; function __construct() { parent::__construct(); } function index() // { $vars['body'] = 'test'; //$this->fuel->page->initialize(array('layout' => 'main')); //$this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'membership')); //$this->fuel->page->add_variables($vars); $this->load->view('membership', $vars); //$this->fuel->pages->render('membership',$vars); } }

As you can see I've tried a few different things. Also, is using CI_Controller correct?

So that does ALMOST what I want, eventually I'll have portions of this module with various forms outputting to the view file which will be inline with the whole site.

Here's the view file I'm using in /modules/membership/views/membership.php:
<?php $this->load->module_view('app', '_blocks/header.php'); if (isset($form)) { // display any form content echo $form; } echo $body; // display any $body content echo 'membership'; $this->load->module_view('app', '_blocks/footer.php');

Seems pretty straightforward doesn't it?

Comments

  • edited February 2013
    For the $js and $css variables to come through, you'll need to use $this->fuel->pages->render()... that pulls in the views/_variables/global.php file? Try adding the following:
    ... $vars['body'] = 'test'; $params['view_module'] = 'membership'; $this->fuel->pages->render('membership',$vars, $params);
  • edited February 2013
    Not sure what I'm missing, I added that, now I just get either a blank page with
    $this->fuel->pages->render('membership',$vars);
    or the following error when I include $params (as it says in the docs):
    Fatal error: Call to a member function call_hook() on a non-object in /home/eng51dev/public_html/restautrade/fuel/modules/fuel/libraries/Fuel_pages.php on line 758

    The docs:
    $this->fuel->pages->render('$location', [$vars=array()], [$params=array()], ['$return'=FALSE])
  • edited 6:05AM
    Ahh, got it! (mostly), I added $vars['layout'] = 'main';

    However, for some reason the $css and $js variables aren't defined still even with that code?

    Though, I have full access to the Site Variables now which is awesome.
  • edited 6:05AM
    I forgot to add the $params as the third parameter in my example above (have edited it). Are the $js and $css values declared in the views/_variables/global.php file?
  • edited 6:05AM
    Yes, they are declared in the application/views/_variables/global.php file.
  • edited 6:05AM
    I added ['js'] = array(); and ['css'] = array(); to the $vars array and that worked. But not sure why it's not pulling from application/views/_variables/global.php though.
  • edited 6:05AM
    I believe if you create a fuel/modules/membership/views/_variables/global.php file with those values in it (perhaps just include the application folders), it should work. The reason is because the setting of the view_module variable affects where FUEL looks for the variable files.
  • edited 6:05AM
    Yeah, that worked.
    What about including js files in the module js folder?
    I tried adding $vars['js'] = array('javascriptfile') but it tried adding it from the application folder.
  • edited 6:05AM
    Try using $vars['js'] = array('membership' => 'javascriptfile');
  • edited 6:05AM
    Perfect! Thanks :)
Sign In or Register to comment.