Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel autoloading module/model throws exception
  • hi, im trying to create a little blog application for getting inside into fuel.
    I created the following structure with Version RC2: modules
    |-blog
    |--classes
    |---controller
    |
    category.php
    |---model
    |
    category.php
    |--views
    |---category
    |----index.php
    |----new.php
    |---template.php Code of index action:
    namespace blog;
    use Orm;
    use Fuel\Core;
    
    class Controller_Category extends \Controller_Template {
    
     /**
      * The index action.
      * 
      * @access  public
      * @return  void
      */
     public function action_index()
     {
      
      $this->template->title = "Category Index";
      
      $data['categories'] = Model_Category::find('all',array('order_by' => array('position' => 'asc')));
     
      $view = \View::factory('category/index',$data);
      $view->set('form',Model_Category::getForm(\Uri::create('blog/category/save')),false);
      $this->template->css = array('uni-form/uni-form.css','uni-form/default.uni-form.css');
      $this->template->content = $view;
     }
    }
    
    With RC2 everything is working fine, but if i update to RC3 i get an exceptipon:
    Fatal error: Class 'blog\Model_Category' not found in /home/dwe/www/dawen-blog/fuel/app/modules/blog/classes/controller/category.php on line 18
    If I replace the /fuel/core/classes/autoloader.php::load class with the one of RC2 everything is working fine again. Is there any namespace thing that i got wrong for calling the Model_Category::find() method ? I hope this is not a multi post in here. greets,
    Daniel
  • Use http://scrip.at/ to post code while they fix the forum. Try putting \ front of the model name.
    $data['categories'] = \Model_Category::find('all',array('order_by' => array('position' => 'asc')));
    
  • Forgot to mention, check the config file to make sure the orm package is unabled in the always_load section.. i don't think you need to use use orm in the controller. hope this helps.
  • Hi Huzzi, i think adding a \ in front of my Model, causes the autoloader trying to include the files from the core classes or the app/contoller section. My Eclipse added the use statement automaticly at this file. Ill try your soultion, if it is working for me tonight. Thanks you for your replies.
  • You shouldn't add the slash when loading the class from the current namespace. I wouldn't use the 'use' keyword, as that would import everything into the current namespace, negating the reason why Fuel uses namespaces in the first place. That shouldn't affect the loading though. Your model class is defined in the blog namespace as well?
  • Yes, I set the namespace for the Model same like the one for the controller. Both classes:
    namespace blog;
    

Howdy, Stranger!

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

In this Discussion