I’ve read through the modules tutorial
http://www.getfuelcms.com/user_guide/modules/simple but I’m not sure when to use the class extending Base_module_record
Using the authors model as an example I have
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Authors_model extends Base_module_model {
// Required fields
public $required = array('name', 'email');
function __construct()
{
parent::__construct('authors');
}
function form_fields($values = array())
{
$fields = parent::form_fields($values);
$upload_path = assets_server_path('authors/', 'images');
$fields['avatar_upload'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE);
$fields['published']['order'] = 1000;
return $fields;
}
}
class Author_model extends Base_module_record {
public function get_avatar_image()
{
return '
avatar).'" />';
}
}
In my controller I then load the authors model and want to get the details of a specific author with id of 1
<?php
class Authors extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->model('authors_model');
// Get author with id of 1
}
}
Do I need to add a function to Author_model or Authors_model?
Comments
$id = 1; // generic find by one $record = $this->authors_model->find_one(array('id' => $id)); //OR find by key $record = $this->authors_model->find_by_key($id);
$record is an instance of your Author_model (which extends Base_module_record). More on working with models can be found here:
http://www.getfuelcms.com/user_guide/libraries/my_model
http://www.getfuelcms.com/user_guide/libraries/base_module_model