Custom Controller for Simple Module

edited February 2013 in Modules
Hi,

I'm new to this FUELCMS, first impression its good! so far liking it.
However i have some concerns regarding the simple module. How to make custom controller for it.

I tried searching other discussion about this, but still i don't know where to start.
Some discussion still not clear to me.

Unfortunately there's no proper documentation about how to create custom controller in simple modules. (if it is possible)

I have created a simple module and i want to upload a csv file with proper data and save it into the database with the help of a controller.

Hope you can help me with step by step how to make it. Thank you in advance.

Comments

  • edited 3:02AM
    You can create a controller anywhere, it just needs to inherit the Fuel_base_controller or if it's a simple module, the module controller (found in fuel/modules/fuel/controllers/) which itself inherits from the Fuel_base_controller. You'll want to create a route probably so that it maps to fuel/{my_module}:
    $route[FUEL_ROUTE.'my_module'] = FUEL_FOLDER.'/my_module'; $route[FUEL_ROUTE.'my_module/(.*)'] = FUEL_FOLDER.'/my_module/$1';
    Alternatively, you can create an advanced module which allows you to house your model, views, controllers, helpers, language files, libraries, etc, in their own folder.
    http://www.getfuelcms.com/user_guide/modules/advanced

    If you are just getting started, I'd recommend taking a look at the 1.0 beta:
    https://github.com/daylightstudio/FUEL-CMS/tree/1.0
  • edited February 2013
    Hi,

    Thanks!
    Its just a simple module, so i think no need to create advance module for it.
    I have added a upload button to my module.

    $config['modules']['regions'] = array( 'preview_path' => 'Home/Contact/Store-Locator', 'list_actions' => array('regions/upload' => lang('btn_upload')), )

    Do i need to create a regions controller in (fuel/modules/fuel/controllers)? and recreate views again? something like

    require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php'); class regions extends Fuel_base_controller { function __construct() { parent::__construct(); } function index() { $vars = array(); $this->_render('regions', $vars); } function upload() { } }

    Thanks.
  • edited 3:02AM
    You will need to create a controller to handle the request. The only exception really is an ajax request where you can automatically map requests that begin with "ajax" to a model method:
    http://www.getfuelcms.com/forums/discussion/comment/2138/#Comment_2138
    However, you can put the controller wherever you need and perhaps an application/controllers/admin/regions.php would be better to keep it out of the fuel folder. You can then create a route for that controller.
Sign In or Register to comment.