FUEL CMS User Guide : Version 1.5.2


Base Module Model Class

Base_module_model is the base class that should be extended when creating modules. The class should be required at the top of your module like so:.

Example


 <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
 require_once(FUEL_PATH.'models/Base_module_model.php');
 class My_super_model extends Base_module_model {
 ...
 

This class extends the MY_Model class.

Properties Reference

Property Default Value Description
public
filters
array()
Filters to apply to when searching for items
filter_value none The values of the filters
filter_join or How to combine the filters in the query (and or or)
parsed_fields
array()
Fields to automatically parse
upload_data
array()
Data about all uploaded files
ignore_replacement
array()
The fields you wish to remain in tack when replacing (.e.g. location, slugs)
display_unpublished_if_logged_in none Determines whether to display unpublished content on the front end if you are logged in to the CMS
list_items_class none A class that can extend Base_model_list_items to help with displaying and filtering the list items
form_fields_class none A class that can extend Base_model_fields and manipulate the form_fields method
validation_class none A class that can extend Base_model_validation and manipulate the validate method by adding additional validation to the model
related_items_class none A class that can extend Base_model_related_items and manipulate what is displayed in the related items area (right side of page)
limit_to_user_field none A user ID field in your model that can be used to limit records based on the logged in user
tables
array('fuel_archives' => 'fuel_archives', 'fuel_blocks' => 'fuel_blocks', 'fuel_categories' => 'fuel_categories', 'fuel_logs' => 'fuel_logs', 'fuel_navigation' => 'fuel_navigation', 'fuel_navigation_groups' => 'fuel_navigation_groups', 'fuel_pages' => 'fuel_pages', 'fuel_pagevars' => 'fuel_page_variables', 'fuel_permissions' => 'fuel_permissions', 'fuel_relationships' => 'fuel_relationships', 'fuel_settings' => 'fuel_settings', 'fuel_tags' => 'fuel_tags', 'fuel_users' => 'fuel_users', )
Cached array of table names that can be accessed statically
protected
CI N/A Reference to the main CI object
fuel N/A Reference to the FUEL object
_formatters N/A

Function Reference [+]

$this->base_module_model->add_filter('$filter', ['$key'=NULL])

Adds a filter for searching.

Returns

void

Parameters

(string) $filter The name of the field to filter on
(string) $key A key to associate with the filter(optional)

$this->base_module_model->add_filters($filters)

Adds multiple filters for searching.

Returns

void

Parameters

(array) $filters An array of fields to filter on

$this->base_module_model->add_filter_join('$field', ['$join_type'='or'])

Adds a filter join such as "and" or "or" to a particular field.

Returns

void

Parameters

(string) $field The name of the field to filter on
(string) $join_type "and" or "or" (optional)

$this->base_module_model->list_items(['$limit'=NULL], ['$offset'=0], ['$col'='id'], ['$order'='asc'], ['$just_count'=FALSE])

Lists the module's items.

Returns

mixed If $just_count is true it will return an integer value. Otherwise it will return an array of data (optional)

Parameters

(int) $limit The limit value for the list data (optional)
(int) $offset The offset value for the list data (optional)
(string) $col The field name to order by (optional)
(string) $order The sorting order (optional)
(boolean) $just_count Determines whether the result is just an integer of the number of records or an array of data (optional)

$this->base_module_model->list_items_total()

Lists the total number of module items.

Returns

int The total number of items with filters applied

$this->base_module_model->filters([$values=array()])

Filter fields to be used to filter the list view data.

Returns

array

$this->base_module_model->friendly_filter_info($values)

Displays friendly text for what is being filtered on the list view.

Returns

string The friendly text string

Parameters

(array) $values The values applied to the filters

$this->base_module_model->archive('$ref_id', $data)

Saves data to the archive.

Returns

boolean Whether it was saved properly or not

Parameters

(int) $ref_id The record ID associated with the archive
(array) $data The array of data to be archived

$this->base_module_model->get_last_archive('$ref_id', ['$all_data'=FALSE])

Retrieves the last archived value.

Returns

array

Parameters

(int) $ref_id The record ID associated with the archive
(boolean) $all_data Determines whether to return all of the archives fields or just the data field value (optional)

$this->base_module_model->get_archive('$ref_id', ['$version'=NULL], ['$all_data'=FALSE])

Retrieves an archived value.

Returns

array

Parameters

(int) $ref_id The record ID associated with the archive
(int) $version The version of the archive to retrieve (optional)
(boolean) $all_data Determines whether to return all of the archives fields or just the data field value (optional)

$this->base_module_model->restore('$ref_id', ['$version'=NULL])

Restores module item from an archived value.

Returns

boolean Whether it was saved properly or not

Parameters

(int) $ref_id The record ID associated with the archive
(int) $version The version of the archive to retrieve (optional)

$this->base_module_model->get_others('$display_field', ['$id'=NULL], ['$val_field'=NULL])

Get other listed module items excluding the currently displayed.

Returns

array Key/value array

Parameters

(string) $display_field The field name used as the label
(int) $id The current value... and actually deprecated (optional)
(string) $val_field The value field (optional)

$this->base_module_model->get_languages(['$field'=NULL])

Returns a key/value array of a distinct set of languages associated with records that have a language field.

Returns

array

Parameters

(string) $field The name of the field used to determine which language. if empty, it will default to 'language' (optional)

$this->base_module_model->replace('$replace_id', '$id', ['$delete'=TRUE])

Replaces an existing record with another record.

Returns

boolean Whether it was saved properly or not

Parameters

(int) $replace_id The old record id of data that will be replaced
(int) $id The new record id of data that will be used for the replacement
(boolean) $delete Determines whether to delete the old record (optional)

$this->base_module_model->export_data([$params=array()])

Returns CSV data that will be downloaded automatically. Overwrite this method for more specific output.

Returns

string

Parameters

(array) $params An array that contains "col", "order", "offset", "limit", "search_term" to help with the formatting of the output. By default only the "col" and "order" parameters are used (optional)

Placeholder for return data that appears in the right side when editing a record (e.g. Related Navigation in pages module ).

Returns

mixed Can be an array of items or a string value

Parameters

(array) $params View variable data (optional)

$this->base_module_model->options_list(['$key'=NULL], ['$val'=NULL], [$where=array()], ['$order'=TRUE])

Overwrites the MY_Model options_list to insert the _common_joins method as a convenience.

Returns

array

Parameters

(string) $key the column to use for the value (optional)
(string) $val the column to use for the label (optional)
(mixed) $where an array or string containg the where paramters of a query (optional)
(mixed) $order the order by of the query. Defaults to TRUE which means it will sort by $val asc (optional)

$this->base_module_model->ajax_options([$where=array()])

Will return an HTML string of option tags which can be used dynamically creating select lists like for "dependent" field types.

Returns

string

$this->base_module_model->get_embedded_list_items($params, [$list_cols=array()], [$actions=array([0]=>edit)])

Generates an HTML data table of list view data for the embedded list view.

Returns

string  The HTML data table

Parameters

(array) $params Params that will be used for filtering & urls (optional)
(array) $list_cols An array of columns to be shown in the data table (optional)
(array) $actions Determines what actions to display. Options are edit, view, delete and custom. Custom is an array of URI => labels (optional)

$this->base_module_model->ajax_embedded_list_items($params)

The ajax method to be called for the embedded list view.

Returns

string The HTML to display

Parameters

(array) $params GET and POST arams that will be used for filtering

$this->base_module_model->form_fields([$values=array()], [$related=array()])

Add FUEL specific changes to the form_fields method.

Returns

array An array to be used with the Form_builder class

Parameters

(array) $values Values of the form fields (optional)
(array) $related An array of related fields. This has been deprecated in favor of using has_many and belongs to relationships (deprecated)

$this->base_module_model->get_module()

Returns the module object for this model.

Returns

object

$this->base_module_model->vars([$data=array()])

A method that will load arbitrary variables to the create/edit view.

Returns

void

Parameters

(array) $data An array of data (optional)

$this->base_module_model->_common_query(['$display_unpublished_if_logged_in'=NULL])

Common query that will automatically hide non-published/active items from view on the front end.

Returns

void

Parameters

(boolean) $display_unpublished_if_logged_in whether to display unpublished content in the front end if logged in

$this->base_module_model->_common_joins()

Placeholder to be overwritten for common joins to be used by _common_query, options_list and list_items methods.

Returns

void

$this->base_module_model->display_name($values)

Function to return the display name as defined by the display_field in MY_fuel_modules.

Returns

string

Parameters

(array) $values $values The values of the current record

$this->base_module_model->on_before_save($values)

Model hook executed right before saving.

Returns

array Returns the values to be saved

Parameters

(array) $values The values to be saved right before saving

$this->base_module_model->on_before_delete('$where')

Model hook executed right before deleting.

Returns

void

Parameters

(mixed) $where The where condition to be applied to the delete (e.g. array('user_name' => 'darth'))

$this->base_module_model->validate('$record', ['$run_hook'=FALSE])

Validate the data before saving. Overwrites the MY_Model::validate() method to look at validation_class property first and run it.

Returns

array

Parameters

(mixed) $record object or array of values
(boolean) $run_hook run on_before_validate hook or not (optional)


Base Module Record Class

This class extends the Data_record class.

Properties Reference

Property Default Value Description
protected
_parsed_fields N/A
_fuel N/A

Function Reference [+]

$this->base_module_record->set_parsed_fields('$fields')

Sets the fields to parse.

Returns

array

Parameters

(string) $fields 

$this->base_module_record->get_parsed_fields()

Returns any fields that should be automatically parsed from the $this->_parsed_fields array.

Returns

array

$this->base_module_record->after_get('$output', '$var')

After get hook that will parse fields automatically.

Returns

string

Parameters

(string) $output 
(string) $var