Changing default admin pages
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
$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
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.
$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