Issues trying to load a model from my controller
  • toymachiner62toymachiner62 February 13
    Ok i may be doing this the codeigniter way and there may be a different/better way to do this in fuelcms, but i am just trying to load a model from a controller and I am getting the error:

    Fatal error: Class 'Base_module_model' not found in /Users/tomcaflisch/Sites/CampbellCustomCoatings-new/trunk/campbellcustomcoatings/fuel/application/models/pattern_categories_model.php on line 3

    Here's my controller:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    Class Pattern_categories extends CI_Controller {

    function __construct()
    {
    parent::__construct();
    }

    function index($categoryId = null)
    {
    // set your variables
    $vars = array('page_title' => 'Check out our list of patterns | Campbell Custom Coatings');

    if(!is_null($categoryId)) {
    //$this->load->model('pattern_categories_model'); // IF I UNCOMMENT THIS LINE I GET THE ERROR
    //$vars['patterns'] = $this->pattern_categories->get_patterns_by_id($categoryId);
    }

    // use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
    $page_init = array('location' => 'pattern_categories', 'render_mode' => 'cms');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
    $this->fuel_page->add_variables($vars);
    $this->fuel_page->render();
    }
    }


    The start of my model looks like this:


    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class Pattern_categories_model extends Base_module_model {

    public $record_class = 'Pattern_category';

    function __construct()
    {
    parent::__construct('pattern_categories');
    }

  • toymachiner62toymachiner62 February 14
    I think i figured it out. I created a new model that extends MY_model and not Base_module_model and it works.

    I take it the problem is that I cannot use a model that extends Base_module_model because those are used for the admin side of things correct?
  • Lance February 14
    You can still use them but you'll need to include the base_module_model before you can extended it.
  • toymachiner62toymachiner62 February 14
    How do I include the base_module_model? My module works fine with this model it's just when I try to call this model from a controller it's throwing the error.
  • adminadmin February 14
    You will need to add a require_once statement including it like so:
    require_once(FUEL_PATH.'models/base_module_model.php');
  • toymachiner62toymachiner62 February 14
    Why didn't I need to include this file to make my module work in the admin?
  • adminadmin February 14
    The model class is probably already required in by a different model and so you don't get the error. It's best to include it at the top just in case.
  • toymachiner62toymachiner62 February 14
    Ok thanks.
  • Here is the response by the server :
    Fatal error: Class 'CI_Model' not found in /Users/michaelsilvestre/git/hightech5/fuel/application/core/MY_Model.php on line 35
  • Lance March 5
    Do you have any code to show how you produced that?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Categories