Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Class 'Orm\Model' not found
  • I come from a CI background, because of that I think FuelPHP is really exciting and it's nice to see progression. This is my first and seemingly only problem with Fuel, and it has been a tough one to get over. I've attempted to generate a scaffold using Oil, and every time I get this error on both my Win7 and OSX machines. The code I run to generate the scaffold seems to work;
    <code>php oil g scaffold posts title:string content:text</code> Part of this is the automatic generation of a model, which looks like this:
    <code><?php class Model_Posts extends Orm\Model { } /* End of file posts.php */</code> Which then generates this error: <b>ErrorException [ Error ]: Class 'Orm\Model' not found</b> Am I missing something?
  • I have the similar problem. I have this following controller :
    modules/user/classes/controller/user.php and the model in :
    modules/user/classes/model/user.php i try to create user model object in controller users.php :
    $new = new model_user(); but, it is generate this following error:
    ErrorException [ Error ]: Class 'user\Model_Users' not found please help, thx ....
  • Have you read what's written above before asking? You probably forgot to add it to the always_load config as is also described in the docs.
  • Make sure it's in the same namespace. Every class in a module has to be in the same namespace. Also, I create new entries like so; $user = Model_User::factory(array(
    'username' => 'ShonM',
    'active' => 1
    )); Instead of new Model_User. Makes it easier when you have thousands of lines of code where the Model_User has its attributes modified several times (for example).
  • I'm getting the same error as ShonM and I've added orm to app/config/config.php
  • Paul Bombo wrote on Tuesday 26th of April 2011:
    I'm getting the same error as ShonM and I've added orm to app/config/config.php

    can you show the code from config? If you try to access ORM from a module, you need to use \Orm\Model (you need to use namespace)
  • 'packages' => array(
    'orm',
    'auth',
    ), thats the relevant part from my config file I'm trying to access my orm models from a controller
  • That should be enough to make the ORM package active. You should not use the ORM from a controller, you should create a model:
    class Model_Test extends \Orm\Model
    {
       // additional configurator or code here
    }
    

    and then in your controller use this model. See the docs (http://fuelphp.com/docs/packages/orm/intro.html) for more information.
  • Also: what is the exact error message? (copy-pasted prefereably)
  • Is the ORM package loaded (app/config/config.php)?
  • OH. Thank you. For some reason I interpreted the package being installed as "active".
  • No, you have to explicitly load it. For performance reasons, Fuel doesn't load anything more than needed.
  • I had this problem as well, I sympathise with linjoo completely. What you are supposed to do here is not clear at all. The documentation eludes to putting packages in your "always_load" section of your config but never explains this. http://fuelphp.com/docs/general/packages.html

    Jelmer also unhelpfully refers to this magical "always_load" section but doesnt provide any example.

    The page which futher confused me was: http://fuelphp.com/docs/general/configuration.html which eludes that the syntax for this is a dot (auto_load.packages).

    There were a lot of examples which say put:
                    'packages' => array(
                        'orm',
                    ),
    in the relevent point in your config.

    What all this boils down to is with a slightly more elaboration I could have saved 2 hours of reading the source from top to bottom. What your config should look like to load the Orm package is:
    <?php
    /**
     * Fuel is a fast, lightweight, community driven PHP5 framework.
     *
     * @package    Fuel
     * @version    1.0
     * @author     Fuel Development Team
     * @license    MIT License
     * @copyright  2010 - 2012 Fuel Development Team
     * @link       http://fuelphp.com
     */

    /**
     * If you want to override the default configuration, add the keys you
     * want to change here, and assign new values to them.
     */

    return array(
            'always_load' => array(
                    'packages' => array(
                        'orm',
                    ),
            ),
    );


  • This has to do with the fact that before 1.4, all config was in your app/config folder. So you would see this structure when you opened the file.

    Because nobody updated their config when upgrading to a new version, we have decided to move all default configuration in the core, so you only need to override defaults in your app/config file, and you start with an empty file.

    This should be clearly mentioned on the general configuration docs page.

    I can imagine that this leads to confusion, I'll try to find the time to go through the docs and clarify this point.


  • This confused me as well. It would be great to see the always_load array mentioned in the documentation for auth and orm, particularly on these pages:
  • When you have things like this, always check the dev-docs, to see if it has already been corrected.

    Which I did for ORM: http://fuelphp.com/dev-docs/packages/orm/intro.html

    I will check other locations refering to config too.

Howdy, Stranger!

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

In this Discussion