Skip to content

Commit

Permalink
removed _template_icons.svg file since it is now embedded in the inst…
Browse files Browse the repository at this point in the history
…all page
  • Loading branch information
David McReynolds committed Apr 6, 2015
1 parent 26b4b14 commit bdbb82e
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 72 deletions.
69 changes: 0 additions & 69 deletions assets/images/_template_icons.svg

This file was deleted.

143 changes: 140 additions & 3 deletions fuel/modules/fuel/views/_docs/modules/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ class which is a child of the MY_Model class and is found in the <dfn>modules/fu
For example, if you have a module's model that has a <dfn>foreign_key</dfn> property to the <dfn>fuel_categories_model</dfn> and a <dfn>has_many</dfn> to the <dfn>fuel_tags_model</dfn>,
tag and category pages can be automatically generated using the <dfn>pages</dfn> parameter.
To make it easier, there is a <dfn>Base_posts_model</dfn> class that your module's model can inherit from (which already inherits from the Base_module_model class).
Below is an example:
</p>

<p>Below is an example of an "articles" module with the pages parameter being used in a module's configuration:</p>
Expand Down Expand Up @@ -408,13 +407,16 @@ class Articles_model extends Base_posts_model {

function list_items($limit = NULL, $offset = NULL, $col = 'publish_date', $order = 'desc', $just_count = FALSE)
{
// add any $this->db->select('....') or $this->db->join(...) here
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
return $data;
}

function form_fields($values = array(), $related = array())
{
$fields = parent::form_fields($values, $related);

// put in your own specific code to manipulate the fields here
return $fields;
}
}
Expand Down Expand Up @@ -443,9 +445,10 @@ class Articles_item_model extends Base_post_item_model {
<li><strong>empty_data_show_404</strong>: determines whether to display a 404 error if the data is empty or not</li>
</ul>
<br>
<p>Lastly, you can of course create your own custom set of pages generated by your module and are not limited to the default.</p>
<p>Lastly, you can of course create your own custom set of pages generated by your module and are not limited to the default. To do this, take advantage of the <dfn>method</dfn> parameter and specify a method
on your model to generate the data you want to pass to your view and specify a relevant <dfn>route</dfn> parameter.</p>

<p>Below is an example of the pages parameter being used in a module's configuration:</p>
<p>Below is an example of the pages parameter being used in a module's configuration with an example of a way to define "custom" generated pages:</p>
<pre class="brush:php">
...
'pages' => array(
Expand All @@ -459,4 +462,138 @@ class Articles_item_model extends Base_post_item_model {
'custom' => array('route' => 'media/custom', 'view' => 'media/list', 'method' => 'my_custom_method')
),
...
</pre>


<h2 id="custom_model_classes">Separate Classes for Model Logic</h2>
<p>For larger models, things like the form_fields method and the validation logic and even the related items area can become a bit much to have in one model. FUEL 1.3 added the ability
to inherit from three new classes to make it easier to separate that logic out. To add this functionality, there are now three new properties that can be utilized on a module model:</p>

<pre class="brush:php">
public $form_fields_class = ''; // a class that can extend Base_model_fields and manipulate the form_fields method
public $validation_class = ''; // a class that can extend Base_model_validation and manipulate the validate method by adding additional validation to the model
public $related_items_class = ''; // a class that can extend Base_model_related_items and manipulate what is displayed in the related items area (right side of page)
</pre>

<h3>Custom Classes</h3>
<p>All custom classes come with the following methods that can be used with the class</p>
<ul>
<li><strong>set_parent_model</strong>: Sets the main parent model (done upon initilaization)</li>
<li><strong>get_parent_model</strong>: Returns the main parent model</li>
<li><strong>set_values</strong>: Sets the current record's values (if any... done upon initialization)</li>
<li><strong>append_values</strong>: Appends values to the existing values store.</li>
<li><strong>get_values</strong>: Returns an array of the values stored</li>
<li><strong>get_value</strong>: Returns a specific value and must pass the key name of the value</li>
<li><strong>record</strong>: Returns a record object of the current records value (if any)</li>
</ul>

<h3>Custom Form Fields Class</h3>
<p>To create your own custom form fields class, specify the class name for the model's $form_fields_class property,
and then create a class that inherits from Base_model_fields (see below).
In the initialize method, you can specify your field logic or even break it out into additional methods to keep it better organized.
The example below does this and creates separate "Info" and "Meta" tabs.
</p>

<pre class="brush:php">
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once(FUEL_PATH.'models/base_module_model.php');

class Articles_model extends Base_module_model {
...
public $form_fields_class = 'Article_fields'; // a class that can extend Base_model_fields and manipulate the form_fields method
...
}

// --------------------------------------------------------------------

class Article_model extends Base_module_record {

// put your record model code here
}

// --------------------------------------------------------------------

class Article_fields extends Base_model_fields {

public function initialize($fields = array(), $values = array(), $parent_model = NULL)
{
$fields =&amp; $this->fields;

$this->set_label('title', 'Headline');

$this->remove(array('date_added'));

$this->info_tab();
$this->meta_tab();
}

public function info_tab()
{
$info_fields = array('title', 'slug', 'content', 'excerpt', 'image');
$this->tab('Info', $info_fields);
}

public function meta_tab()
{
$meta_fields = array('tags', 'category_id');
$this->tab('Meta', $meta_fields);
}
}
</pre>
<p>The <dfn>Base_model_fields</dfn> class provides the follow additional methods:</p>
<ul>
<li><strong>set_fields</strong>: Sets the fields for the object and happens upon initialization</li>
<li><strong>get_fields</strong>: Returns an array of field information</li>
<li><strong>get_field</strong>: Returns a single field's information</li>
<li><strong>set</strong>: Sets a field's information</li>
<li><strong>get</strong>: Returns a single field's information</li>
<li><strong>remove</strong>: Removes a field</li>
<li><strong>tab</strong>: Creates a tab with the specified fields</li>
<li><strong>clear</strong>: Clears the field information</li>
<li><strong>reorder</strong>: Reorders the fields in the specified order</li>
</ul>
<p>Note that in the example above the various ways to conveniently set field properties using the "set_" magic method. You can mass assign values to multiple fields.
Below is an example of how to hide multiple fields at once:</p>
<pre class="brush:php">
$this->set_type(array('field1', 'field2'), 'hidden');
</pre>

<p>Additionally you can specify a single property by passing an array:</p>
<pre class="brush:php">
$this->set_comment(array('field1' => 'Comment 1', 'field2' => 'Comment 2'));
</pre>

<p>Lastly, you can just create a single field value using just the <dfn>set</dfn> method:</p>
<pre class="brush:php">
$this->set('field1', array('label' => 'Field 1 label', 'type' => 'textarea'));
</pre>


<h3>Custom Validation Class</h3>
<p>A custom validation class is convenient for separating your model validation logic outside of your model class. The following are additional methods that can be used on the validation class:</p>
<ul>
<li><strong>add</strong>: Adds a validation rule using the <a href="<?=user_guide_url('libraries/validator')?>">Validator</a> class that is set on the parent model</li>
<li><strong>remove</strong>: Removes a validation rule</li>
<li><strong>validate</strong>: Runs through the validation rules to validate</li>
</ul>

<h3>Custom Validation Class</h3>
<ul>
<li><strong>add</strong>: Adds a validation rule using the <a href="<?=user_guide_url('libraries/validator')?>">Validator</a> class that is set on the parent model</li>
<li><strong>remove</strong>: Removes a validation rule</li>
<li><strong>validate</strong>: Runs through the validation rules to validate and returns a boolean value</li>
</ul>

<pre class="brush:php">
...
class Article_validation extends Base_model_validation {

public function initialize($record, $parent_model)
{
// passing additional parameters can be done either as a colon after the key in a second array parameter or in an array as the 4th option)
$this->add('submitted_by_id', 'is_equal_to', 'The submitter ID needs to equal 2', array(2));
$this->add('submitted_by_id', array('is_equal_to:2' => 'The submitter ID needs to equal 2'));
}
}
</pre>

0 comments on commit bdbb82e

Please sign in to comment.