Extending fuel_pages_model

edited May 2013 in Modules
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

  • edited 5:14PM
    To use a different model for the pages module you can use the modules_overwrites key in the MY_fuel_modules.php file like so:
    $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;
  • edited 5:14PM
    (I'm using v1 by the way)

    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.
  • edited 5:14PM
    Hmm.. I'm not seeing that error. I have the following class in the application/models folder which is getting loaded when the the $config['module_overwrites']['pages'] is used above.
    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; } }
  • edited 5:14PM
    I fetched a fresh copy of Fuel, set up, and tried what you have (I omitted the FUEL_FOLDER constant in the $has_many array 1st time round)...

    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?
  • edited 5:14PM
    I think I see the issue now. You are right in that it had to do with the belongs_to value being set in the fuel_tags_model. I've posted a fix for that in the 1.0 branch.
  • edited 5:14PM
    That's a nice fix - with the extended class it's great addition to pages! Thanks!
  • edited 5:14PM
    As an FYI, I ran into some issues with CKEditor in pages with 'auto_execute_js' set to TRUE.
Sign In or Register to comment.