Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Hello
  • I've just switched from CI to FUEL, and start playing with this nice framework.
    I've just blocked to modules section, and i have a problem understanding how models are loaded inside modules. I've created a module named test.
    I've created a controller named Welcome
    I've created a model named users. Controller code looks like that: namespace Test;
    use \Model\Users; class Controller_Welcome extends \Controller {
    public function action_index()
    {
    $result = Users::list_users( array( 1, 3, 5, 6, 7 ) );
    return TRUE;
    } }
    Model code looks like:
    namespace Model; class Users extends \Model {
    public static function list_users( $data )
    {
    // some data here...
    return $data;
    } }
    And the error is... ErrorException [ Error ]: Class 'Model\Users' not found.
    best regards,
    Paul.
  • Where exactly did you create this model? A module is in essence nothing more then a namespace that maps to a location on disk. if you have created this model in /app/classes/model, that this is absolutely correct. If you have created the model in modules/test/classes/model, then it's wrong. Every class in a module must be in the module namespace (or a sub-namespace). So if you have created it in the module, it should be
    namespace Test\Model;
    
    class Users extends \Model {}
    

    And in your controller
    namespace Test;
    use Model\Users; // note NO leading slash, it's relative to the controller namespace !
    
  • Thank you.

Howdy, Stranger!

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

In this Discussion