Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Model_Users and Module Models folder
  • Hey, im building my first Fuel app and although im learning alot as I go this one issue is perplexing me. I have decided to use Modules for most of the app as I prefer the HMVC organisation, however <code>$current_user = \Model_Users::find_by_username( \Auth::get_screen_name());</code> throws an exception and doesnt want to be found unless its places in /app/classes/models/. As this is wrong I was wondering if anyone had an idea how to fix it so I can use modular models and refer to them around the app. Ive been searching for any solution, reading the fuel blog articles and generally trying everything I can think of, but im not fresh out of ideas. The Module is found in /modules/users
    It has:
    /classes/controllers
    /classes/models (this is the one that doesnt work)
    /views/ the top of the users.php (which is only found in fuel/app/classes/models/ is very simple and looks like:
    <code>
    <?php class Model_Users extends \Orm\Model
    {
    protected static $_properties = array(
    'id',
    'username',
    'password',
    'group',
    'companyid',
    'email',
    'last_login',
    'login_hash',
    'remember_me',
    'profile_fields',
    'created_at',
    'updated_at'
    );
    </code> ... any help would be awesome... :)
  • Everything in the module must be namespaced with that module. Thus it's full name would be Users\Model_Users.
    <?php
    
    namespace Users;
    
    class Model_Users extends \Orm\Model {
    //...etc
    

    One final note: it's common convention to name models singular, this is because each instance of the class will represent a single "user" in this case and not multiple. Thus making the following examples more logical code:
    $user = new Users\Model_User();
    $user instanceof Users\Model_User;
    
  • Hi Jelmer, thanks for answering so quick and for the namespacing tip, its all making alot more sence now.

Howdy, Stranger!

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

In this Discussion