Changing default admin pages

edited July 2014 in Modules
Hi, i want to modify the current "page" in the admin control panel to include one additional column such as "Category" and modify the display of the listing by grouping according to the category. Which file should i edit to make this happen? Actually i mean can i just write the controller files and view files under application folder and it will overwrite the default pages.php controller? i need to consider the ease of upgrade in the future.

Comments

  • edited 12:24AM
    If you want to modify an existing simple module like pages, you can use "module_overwrites" which are found in the fuel/application/config/MY_fuel_modules.php file. You'll see that there are probably already 2 there for hiding the categories and tags modules. You can modify an existing module's "model" like so:
    $config['module_overwrites']['pages'] = array( 'model_name' => 'my_pages_model', 'model_location' => 'app');
    This then points to a model that you can use to overwrite existing functionality. In this case, it sounds like you want to modify the list_items method which is used to render the list view. Below is an example of doing that which modifies the columns being displayed by altering the returned results using the db->select(...).
    require_once(FUEL_PATH.'models/fuel_pages_model.php'); class My_pages_model extends Fuel_pages_model { public $has_many = array('tags' => array('model' => array(FUEL_FOLDER => 'fuel_tags_model'))); function list_items($limit = NULL, $offset = 0, $col = 'id', $order = 'asc', $just_count = FALSE) { $this->db->select('fuel_pages.id, fuel_pages.location, fuel_pages.layout, my_table.categories, fuel_pages.published'); $data = parent::list_items($limit, $offset, $col, $order, $just_count = FALSE); return $data; } }
    To modify the display so that it's grouped, you can add an additional "filters" parameter to the "module_overwrites" like so:
    $config['module_overwrites']['pages'] = array( 'model_name' => 'my_pages_model', 'model_location' => 'app', 'filters' => array('category' => array('type' => 'select', 'options' => array('category1' => 'category1', 'category2' => 'category2', 'category3' => 'category3')) );
    Alternatively, for "filters" options, you can specify a model to dynamically generate the list:
    $config['module_overwrites']['pages'] = array( 'model_name' => 'my_pages_model', 'model_location' => 'app', 'filters' => array('category' => array('type' => 'select', 'model' => 'my_model') );
    http://docs.getfuelcms.com/modules/simple
  • edited 12:24AM
    because we have one to many relationship, which means one category will have multiple pages. so i added public $foreign_keys = array('category_id' => array(FUEL_FOLDER => 'categories_model'))) in my new page model.
    however, one question, i have added the category selection in the page variables table. Adding foreign key in new page model result in the fuel_categories.name not found.
  • edited 12:24AM
    Try using "fuel_categories_model" instead of just "categories_model"
  • edited 12:24AM
    I actually used default fuel_categories table for the categories table. However, the column of categories is not shown when listing out the pages on page module. Basically what i do now is to modify MY_fuel_modules.php add


    $config['module_overwrites']['pages'] = array(
    'model_name' => 'sk_pages_model',
    //'filters' => array('category'=>array('type'=>'select', 'model'=>'fuel_categories')),
    );

    Then for sk_pages_model.php add

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


    class sk_pages_model extends Fuel_pages_model {
    public $foreign_keys = array('category_id' => array(FUEL_FOLDER => 'fuel_categories_model'));

    function list_items($limit = NULL, $offset = 0, $col = 'id', $order = 'asc', $just_count = FALSE){
    $this->db->select('fuel_pages.id, fuel_pages.location, fuel_pages.layout, fuel_pages.last_modified, fuel_pages.published, fuel_categories.name AS categories')->join('fuel_categories','fuel_pages.category_id=fuel_categories.id');

    $data = parent::list_items($limit, $offset, $col, $order, $just_count = FALSE);

    return $data;
    }
    }

    $data returned query result correct, however the front end list table no categories column, please help. thanks
  • edited 12:24AM
    There is a parameter in the module called "table_headers" that if set, will limit the list items to just the fields specified no matter what the query returns. Try adding this to your overwrites as well. See the original in fuel/modules/fuel/config/fuel_modules.php
  • edited July 2014
    thanks, solved
Sign In or Register to comment.