Loading the Model In Controller
I'm kind of unclear as to how to do this with FUEL. I decided to use the regular CodeIgniter controller/view process of displaying information. So referencing the model from the controller should be as simple as $this->load->model('foo'). But for some reason it isn't working. I'm calling this from within the index() method of the CI_Controller (or the class that extends it).
Comments
Here is my controller.
<?php
class ArtsJournals extends CI_Controller{
function __construct()
{
parent::__construct();
}
function index()
{
// use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
$page_init = array('location' => 'artsjournals', 'render_mode'=>'cms');
$this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
$this->fuel_page->add_variables(array('layout'=>'pagelayout'));
$this->fuel_page->render();
$this->load->model('categories_model');
$data = array();
// remember, all categories that have a published value of 'no' will automatically be excluded
$categories = $this->categories_model->find_all();
foreach($categories as $category)
{
$data[$category->name]=array();
foreach($category->articles as $article)
{
$data[$category][$article->title] = array
(
"title" => $article->title,
"content" => $article->content,
"date_added" => $article->date_added,
"image" => $article->article_image,
"subcontent" => $article->pulloutquote
);
}
}
$this->load->view("artsjournals", $data);
//echo $categories;
}
}
Not sure why this isn't working.
Also, as an FYI, FUEL 1.0 beta has an updated tutorial using the 1.0 branch (which has ton of extra features including automatic relationships with has_many and belongs_to).
https://github.com/daylightstudio/FUEL-CMS/tree/1.0
http://docs.getfuelcms.com/modules/tutorial
http://docs.getfuelcms.com/general/models
So if my model is:
class Foo extends Base_module_model
{
public customFunction(){
}
}
saved in file foo.php in the "models" directory.
I'm suppose to be able to call that function in the controller like:
$foomodel = $this->load->model('foo')
$this->foomodel->customFunction();
At least that how I thought it worked. Correct?
I had:
$categories = $this->load->model('categories_model');
then..
foreach ($categories as $category) ..etc
I wasn't suppose to assign the model class to a