Extending fuel_pages_model
Hello,
I want to add properties like "has_many" to cms pages in v1. In v0.93 I worked out a way, but it involved editing the core Fuel model files. Now I'd like, if possible, to find a more loosely coupled solution.
How would I (can I?) extend fuel_pages_model? I tried extending using the autoload to get the new, modified model, but that hasn't proved workable.
Incidentally, I did try adding the property directly to the fuel_pages_model, but the internal db table is "pages" not "fuel_pages" and the tag field example breaks badly! Eg
public $has_many = array('tags' => 'fuel_tags_model');
gives a semi broken tags combo (ie just the "tags" half), but if you then try to add tags, via the tags module, there is a SQL error connecting to a "pages" table.
Comments
$config['module_overwrites']['pages'] = array('model_name' => 'my_pages_model', 'model_location' => 'app');
Are you using 1.0 or 0.93? If 1.0, and you are using the multi select combo, javascript is not set to execute for the page specific fields (location, layout, cache, published). To turn it on, you'll need to add the following in your my_pages_model's form_fields method.
$fields['__FORM_BUILDER__']['auto_execute_js'] = TRUE;
OK, finally got round to trying your suggestions (creating an extension of Fuel_pages_model), and... there is still a problem regarding the tags association - if, after making the changes above, I try to create a tag there is an error:
An Error Was Encountered Unable to locate the file: pages_model.php
This should be MY_fuel_pages_model (which I have in application/models). I suppose on reflection the MY prefix is irrelevant here.
The good news is that the tag combo in pages create / edit doesn't appear broken, but if I try to "add" a tag from there, the same problem occurs as for creating tags using the tags module - the "pages_model" is not found.
require_once(FUEL_PATH.'models/fuel_pages_model.php'); class My_pages_model extends Fuel_pages_model { public $has_many = array('tags' => array(FUEL_FOLDER => 'fuel_tags_model')); function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); $fields['__FORM_BUILDER__']['auto_execute_js'] = TRUE; return $fields; } }
but
when creating a tag - either through the combo select of the 'pages' create /edit page, or through the tags module, I (still) get
An Error Was Encountered Unable to locate the file: pages_model.php
I think 'pages' is being passed to MY_model as the belongs_to value?