Controller for home page

edited September 2011 in Installation
I'm new to fuel, but not to CodeIgniter. I'm starting on a project using Fuel for the first time. I created a page called "home" via the CMS using a custom layout I made based on the default layout. That all works fine. In my layout, I have some spaces where I want to fill with some generated content which I plan to do with fuel variables. I created a controller called home.php, the code for this is as follows:

class Home extends CI_Controller {

function __construct() {
parent::__construct();
}

function index() {
$vars = array();
$vars['top_content_block'] = "This is top content";

// use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
$page_init = array('location' => 'home');
$this->load->module_library( FUEL_FOLDER, 'fuel_page', $page_init );
$this->fuel_page->add_variables( $vars );
$this->fuel_page->render();
}
}

When going to the sites main page just using the domain name, the regular home page still comes up. But when trying to go to /home, I just get a blank page. I've put some debugging in there and it's definitely getting to my controller.

My $config['fuel_mode'] variable is set to "auto".

I guess some of the questions I have are:

1) If I create a page via the CMS, can I create a controller for it and still have fuel use the layouts and content stored in the db? Is that the purpose of the last three lines in the controller?

2) My goal is to create most pages with some editable content and some programmed content. The owner of the site is not XHTML/CSS savvy and I want him to be able to edit some content, so my plan was to create different layouts for the different types of page designs, then use controllers to add the content I need to add, but have fuel render the pages and pull the edited content from the db and use the layouts. Should what I'm thinking be doable and anything special I need to know?

Thanks,
Bruce

Comments

  • edited 6:28PM
    Ok, I think I got this page to work by setting some additional values in the $page_init array. I set 'layout' and 'render_mode' and now it brings up the page with my added comtent.

    However, when going to the root of the site without the "/home", it doesn't seem to be using my controller even though the default home page is set to "home". Is there a way to fix that? I'm sure I can always redirect root requests to the "/home" url via mod_rewrite, but is there a better way using fuel itself?

    Bruce
  • edited 6:28PM
    What happens if you change the "default_controller" in the routes to "home"
  • edited 6:28PM
    Yes, that makes it all work, thanks. I forgot about the basic CI setting for this. Guess I was too focused on the Fuel additions :)

    Bruce
  • edited 6:28PM
    Hello, I am having similar issues. I created a home inside the CMS, also note that I have left the default home.php still in the view folder. I changed the default_controller to home. The CMS notifies me that a Controller exist for this page. And when I try to view home, it still comes up with the initial FuelCMS home page... any ideas?
  • edited 6:28PM
    This link has been really helpful - http://www.getfuelcms.com/forums/discussion/729/routing-and-home-page-controller/p1. Got the home working using the CMS but when I add a Controller it then takes it to a blank page even though I have specified the location:

    function index()
    {

    $data = array();
    $data['view'] = 'home/index';
    $page_init = array('location' => 'home');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
    $this->fuel_page->add_variables($data);
    $this->fuel_page->render();
    }
  • edited 6:28PM
    This helped as well - http://www.getfuelcms.com/forums/discussion/249/empty-page-is-rendered-when-creating-a-controller./p1.

    Home page created in CMS with Controller works!
Sign In or Register to comment.