How to tell Fuel where to look for a model file when creating a Simple Module

edited February 2012 in Modules
I am attempting to hook up a model file that directly maps to a single database table called "subscription_types". The simple module tutorial instructs that the "subscription_types_model.php" file be placed in /fuel/application/models, but I want to know how to get this module to show up in the Fuel Admin if I were to place this file in this location:

/fuel/modules/corporate_partners/models

Right now I get an error saying "Unable to locate the file: subscription_types_model.php" so I'm wondering how would I wire this up from this location and is it possible?

Thanks,
Erik

Comments

  • edited 1:34AM
    I would create a /fuel/modules/corporate_partners/config/corporate_partners_fuel_modules.php and put your module configuration in there if you haven't already. You'll also need to specify the 'model_location' => 'corporate_partners', in that file similar to the /fuel/modules/blog/config/blog_fuel_modules.php

    Also, add "corporate_partners" to your "allowed_modules" configuration parameter in MY_fuel.php
  • edited 1:34AM
    Ok, I've done all of the steps you outlined, but I am still getting a 404 error when trying to access /fuel/corporate_partners/subscription_types, which is the location I would prefer for accessing the subscription_types table view in order to edit the data.

    Here is my corporate_partners_fuel_modules.php file:

    $config['modules']['corporate_partners'] = array( 'module_name' => 'Corporate Partners', 'module_uri' => 'corporate_partners', 'model_name' => 'corporate_partners_model', 'model_location' => 'corporate_partners', 'table_headers' => array( 'id', 'name', 'key', 'password', 'subscription_type_id', 'contact_name', 'contact_email' ), 'display_field' => 'name', 'permission' => 'corporate_partners', 'instructions' => lang('module_instructions_default', 'corporate partners'), 'archivable' => FALSE, 'nav_selected' => 'corporate_partners', ); $config['modules']['subscription_types'] = array( 'module_name' => 'Subscription Types', 'module_uri' => 'corporate_partners/subscription_types', 'model_name' => 'subscription_types_model', 'model_location' => 'corporate_partners', 'table_headers' => array( 'id', 'name', 'cost_per_subscriber', 'subscriber_cost', 'type' ), 'display_field' => 'name', 'permission' => 'corporate_partners', 'instructions' => lang('module_instructions_default', 'subscription types'), 'archivable' => FALSE, 'nav_selected' => 'subscription_types', );

    I have added this code to my config/corporate_partners.php file (for the left-hand navigation):

    $config['nav']['corporate_portal'] = array( 'corporate_partners' => 'Corporate Partners', 'corporate_partners/subscription_types' => 'Subscription Types', );

    What am I doing wrong if it gives me a 404 when accessing /fuel/corporate_partners/subscription_types?
  • edited February 2012
    Also, here is the code i have in the models/subscription_types_model.php file:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Subscription_types_model extends Base_module_model { function __construct() { parent::__construct('subscription_types'); } } class Subscription_type_model extends Base_module_record { }

    My end goal in all of this is to have an umbrella module called "corporate_partners" that resides at fuel/modules/corporate_partners and to also have 2 sub-modules, one also called "corporate_partners" that has a model file that directly maps to the corporate_partners table and a module called "subscription_types" whose model maps to the subscription_types table. I would like to be able to edit the data in both of these tables via the Fuel interface.

    Let me know if I've thought this through correctly based on the design of the module feature of Fuel.
  • edited 1:34AM
    I got it working by starting from scratch in a sense. I removed the corporate_partners_fuel_modules.php and corporate_partners_routes.php just to get a clean slate and then I modified MY_fuel_modules.php to contain this:

    $config['modules']['subscription_types'] = array( 'module_name' => 'Subscription Types', 'module_uri' => 'subscription_types', 'model_name' => 'subscription_types_model', 'model_location' => 'corporate_partners', 'display_field' => 'name', 'permission' => 'subscription_types', 'instructions' => lang('module_instructions_default', 'subscription types'), 'archivable' => FALSE, 'nav_selected' => 'subscription_types' );

    That got it to work finally :).

    So here's my next question. I liked how I was able to customely define the Fuel navigation for the Corporate Partners module. The change I made above to the MY_fuel_modules file however, exposes the "Modules" option on the left hand side. I would like that to go away and instead have a custom navigation that I have defined in the config/corporate_partners.php file which changes the word "Modules" in the left-hand side to say "Corporate Partners".

    I am able to expose this custom menu if I define the navigation structure for the menu in config/corporate_partners.php AND allow the corporate_partners module in MY_fuel.php. So the thing I would like to know is how do I hide the "Modules" menu from the Fuel navigation?
  • edited 1:34AM
    add "hidden" => TRUE to the configuration
  • edited 1:34AM
    That was too easy, thanks!
Sign In or Register to comment.