Base Controller for jQuery Slider
I'm at it again. 4th Fuel project and this time I want a jQuery Slider on Evvverryyyy page.. However, the data is coming from a database so I've added my class to the MY_controller.php file as I would do in codeigniter to create a base controller. This works fine on pages with their own controller that use this method to render the page:
$page_init = array('render_mode' => 'cms');
$this->fuel->pages->render('home', $this->vars, $page_init);
the problem is.. the pages that come directly out of the CMS and don't have their own controller and crash b/c the render method isn't being passed in $this->vars...
/* The MX_Controller class is autoloaded as required */
class MY_Controller extends CI_Controller {
public $vars;
function __construct()
{
parent::__construct();
$this->load->model('Slider_model');
$this->vars['homepage_sliders'] = $this->Slider_model->GetSliders();
}
}
Comments
http://docs.getfuelcms.com/general/pages-variables
Also, something to consider, instead of creating a model for your slider, you could create a page layout that uses a template field that's repeatable. This allows you to have a set of fields (images, image alt, etc) that can be reordered around. We do this quite a bit for pages that have an image slider.
http://docs.getfuelcms.com/general/forms#template
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* The MX_Controller class is autoloaded as required */
class MY_Controller extends CI_Controller {
//public $vars;
function __construct()
{
parent::__construct();
$this->load->model('Slider_model');
//$this->vars['homepage_sliders'] = $this->Slider_model->GetSliders();
$vars['homepage_sliders'] = $this->Slider_model->GetSliders();
}
}
<?php
class Home extends MY_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$page_init = array('render_mode' => 'cms');
$this->fuel->pages->render('home', $vars, $page_init);
}
}
/* end of class */
It can't find $vars... How do I make this work? .. and how do I make it work on the CMS without controllers?
$this->fuel->pages->variables(['$key'=NULL]);
????
$vars = $this->fuel->pagevars->retrieve($location);
This will retrieve any variables assigned in a variables file or in the CMS.
BaseController->HomeController-> (WORKS)
->Golf Page (CMS Page / No Controller / Does not work)
How do I get the base controller to inject $vars data into a CMS page that does not have a controller, basically a CMS page....
http://docs.getfuelcms.com/general/layouts
That's too bad I can't use the base controller to do this... This should be implemented in the future so I won't have to do these hacks..
I would like to make a shopping cart for Fuel.
$CI->load->model('slider_model'); $vars['sliders'] = $CI->slider_model-> GetSliders();