Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem Accessing Model Class
  • Hello there, I am getting a peculiar error: "Class 'Model_Article' not found". My model is in the models directory provided with Fuel, however my controller cannot seem to find it. I have not deviated from any Fuel connections, such as naming my model with the "Model_" prefix. My controller is in the controllers folder Any help would be greatly appreciated! My controller:
    <?php
    
     class Controller_admin_dbtest extends Controller_Template &#123;
     
     
     public $template = 'template_backend';
    
        public function action_index()
        &#123;
         $articles = Model_Article::find('all');
            $data = array();
            $this->template->content = View::factory('admin/test', $data);
        }
        
        public function action_404()
     &#123;
      $messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
      $data['title'] = $messages[array_rand($messages)];
    
      // Set a HTTP 404 output header
      $this->response->status = 404;
      $this->response->body = View::factory('welcome/404', $data);
     }
    } 
    
    ?>
    

    My Model
    <?php
    
    
     class Model_Article extends Orm\Model
     &#123;
      protected static $_properties = array('articleID', 'articleTitle');
      protected static $_primary_key = array('articleID');
      
      public function retreiveArticles()&#123;
      
      }
    
     }
    
    ?>
    
    
  • Are your paths & filenames fully lowercased? (paste those as well, just to check)
  • Jelmer Schreuder wrote on Sunday 8th of May 2011:
    Are your paths & filenames fully lowercased? (paste those as well, just to check)

    Well, I decided to scrap what I was working on above and opt to use the oil command to get things running. It seems that, now, it can find my model. However, I am getting this error now:
    ErrorException [ Notice ]: Undefined index: id PKGPATH/orm/classes/query.php @ line 553:
    552: &#123;
    553: if (is_null($obj[$pk]))
    554: &#123;
    

    Below that error message, my template displays fine. However, nothing from the database is displayed, etc. I am not sure why "id" is not found, or where "id" even comes into play, as I do not have any variable / column named "id". Thank you for your time, I really appreciate it! Controller: (controller/admin/new.php)
    <?php
    
     class Controller_Admin_New extends Controller_Template &#123;
     
     public $template = 'template_backend';
    
        public function action_index()
        &#123;
            $data['articles'] = Model_Article::find('all');
            $data['adminUserName'] = "Jeremy Buff"; 
            $data['adminRole'] = "Lead Developer";
            $this->template->title = 'Full Sail Times';
            $this->template->content = View::factory('admin/new', $data);
        }
        
        public function action_404()
     &#123;
      $messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
      $data['title'] = $messages[array_rand($messages)];
    
      // Set a HTTP 404 output header
      $this->response->status = 404;
      $this->response->body = View::factory('welcome/404', $data);
     }
    } 
    
    ?>
    
    
    Migration: (migrations/001_create_articles.php)
    <?php
    
    namespace Fuel\Migrations;
    
    class Create_articles &#123;
    
     public function up()
     &#123;
      \DBUtil::create_table('articles', array(
       'articleID' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
       'articleTitle' => array('constraint' => 65, 'type' => 'varchar'),
       'articleExcerpt' => array('constraint' => 350, 'type' => 'varchar'),
       'articleBody' => array('type' => 'longtext'),
       'startDate' => array('type' => 'datetime'),
       'endDate' => array('type' => 'datetime'),
       'modDate' => array('type' => 'datetime'),
       'authorID' => array('constraint' => 11, 'type' => 'int'),
    
      ), array('articleID'));
     }
    
     public function down()
     &#123;
      \DBUtil::drop_table('articles');
     }
    }
    
    
    Model: (model/article.php)
    <?php
    
    class Model_Article extends Orm\Model &#123; }
    
    /* End of file article.php */
    
    
  • If your primary key is anything other than "id" you need to set it in your class definition, check the docs.
  • Jelmer Schreuder wrote on Sunday 8th of May 2011:
    If your primary key is anything other than "id" you need to set it in your class definition, check the docs.

    Ah, I see. That makes sense. Thank you for your time. For your help, I would like to donate to the project, if you accept donations. I see the contribute page, but I do not see anything about donations. Please let me know how I may financially contribute to Fuel. Thanks again!
  • There used to be one to help Dan out with the hosting costs, will ask him about that. But biggest help is what we say under contribute: help us out with bughunting, bugfixing, writing unit tests & writing/improving documentation.

Howdy, Stranger!

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

In this Discussion