Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
A Little Bit More Info About Models
  • In docs there aren't a lot of info about models. I have a couple of questions to you, guys. 1) Any specific rules for model's file name?
    2) Any specific rules for model's class and methods prefixies?
    3) What it should extend? Is it required?
    4) How to call it from controller?
  • 1. They follow the same rules as controllers do.
    2. The model's class has the prefix 'Model_', so if I wanted my model to be called 'article' I would make it 'Model_Article'
    3. It should extend the Model class, as such:
    class Model_Article extends Model {}
    
    4. Just call it like you would normally - everything is autoloaded in Fuel:
    class Controller_Home extends Controller {
    
        public function action_index()
        {
            $articles = Model_Article::find('all');
        }
    }
    
  • Thanks. All works. =]
  • 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. Any help would be greatly appreciated! My controller:
    public function action_index()
        {
         $articles = Model_Article::find('all');
            $data = array();
            $this->template->content = View::factory('admin/test', $data);
        }
    
  • I thought they were formatting buttons too, but they're not. I believe they just indicate the html tags that can be used. So put the code between <code> and </code> tags.
  • Mitchell Steinberg wrote on Sunday 8th of May 2011:
    I thought they were formatting buttons too, but they're not. I believe they just indicate the html tags that can be used. So put the code between <code> and </code> tags.

    Ah, I see. I tried <code> but that didn't work, it's actually "code" in brackets. Thanks!

Howdy, Stranger!

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

In this Discussion