Controller function for all views

edited February 2014 in News & Announcements
Hi Fuel forum, something I was wondering about. The code below represents a function that allows me to create a new view from the CMS. This code is in the controller that my website uses.

function funjetvalentinesdaysale() {
$data = array();
$data['my_custom_content'] = '';
$data['view'] = 'funjetvalentinesdaysale';
$page_init = array('location' => 'funjetvalentinesdaysale', 'render_mode' => 'cms');
$this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);

In my website, the above code structure is used every time I want to create a new view. This website has over 30 views, so try to imagine 30+

function whatever() {
// Do stuff here

My question is would it be possible to write a kind of universal function that would eliminate my need to write a function for every view I make? Appreciate the help in advance.


  • edited 5:00PM
    Hmm... why are you creating a controller method instead of letting it render normally through the CMS?
  • edited February 2014
    Because everything about this site is dynamic. Basically what happens with this site is it loads specific content based on the url that is used. The url that is used is based on a model which has a multitude of database queries. All the dynamic content has to be loaded from a model which is then passed to a controller, and finally into a view.

    Example url:

    The number where the www should be is a number assigned to a travel agent. Without a number in place of www, Codeignitor and Fuel doesn't know what to load and reverts to an error page.
  • edited 5:00PM
    Is there a way to extract out functionality into a base controller class and/or base the view on the URI path so that is dynamically set by something like the uri_path() function? Or perhaps use something like the _remap method on the controller:
Sign In or Register to comment.