Using Codeigniter Models

edited September 2017 in Share
Trying to get an existing CI model that pulls info from a database (do not want to make a fuel_model for it, since it's content that is read-only, and comes from another source).

Tried adding the model to fuel/application/views/_variables/training.php

inside, added the content:

<?php $vars['models'] = 'training_model';

The content can be pulled in a view (the fuel/application/views/_blocks/header.php

I cannot get this data to be show in a fuel CMS page. It pulls the body fuel_var('body', 'This is a default layout..

Is there any way to pass this data pulled into a given page in the CMS?

Comments

  • edited 9:25AM
    What is the code in the header.php file for creating the model instance and grabbing the correct training model record?
  • edited 9:25AM
    I think I found a way to get around it.

    Create a page in the fuel/application/_variables with the same name as the URL. (training.php).

    Include the model ($this->load->model('training_model');)

    On the layouts, use the model as normal:

    $something = $this->training_model->get_courses();
    fuel_set_var('something', $something);

    Then in the page, or the block, the variable $something is available.

    It seems to work for me, maybe it's not the cleanest way, but it gets the job done.
  • edited 9:25AM
    That is one way to do it. If you have a lot of logic you would like to keep out of the views, you can use a controller or create a layout class with a pre_render function that encapsulates that logic.
    http://docs.getfuelcms.com/general/opt-in-controllers

    http://docs.getfuelcms.com/general/layouts (as discussed under Layouts As Their Own Class Files)
Sign In or Register to comment.