Using Codeigniter Models
  • 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';<br />
    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?
  • What is the code in the header.php file for creating the model instance and grabbing the correct training model record?
  • 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.
  • 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. (as discussed under Layouts As Their Own Class Files)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!