Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
slightly modifying OrmAuth to add slug column
  • How would I go about extending/modifying the model in order to add a slug column to the users table without touching the original user.php file in packages/auth/classes/model? I briefly looked at the documentation to extend an auth package but this has nothing to do with login, groups or ACLs...
  • The Auth package is handled as a core namespace, and aliased to global, so you can extend any class in it.

    create app/classes/model/auth/user.php:

    namespace Model;
    class Auth_User extends \Auth\Model\Auth_User {}

    and don't forget to add the class to your app/bootstrap.php (as documented, see http://docs.fuelphp.com/general/extending_core.html#extend_from_packages
  • I've followed those instructions but it's not working...

    app/classes/model/auth/user.php:
    namespace Model;

    class Auth_User extends \Auth\Model\Auth_User
    {
    protected static $_observers = array(
    'Orm\\Observer_CreatedAt' =--> array(
    'events' => array('before_insert'),
    'property' => 'created_at',
    'mysql_timestamp' => false
    ),
    'Orm\\Observer_UpdatedAt' => array(
    'events' => array('before_update'),
    'property' => 'updated_at',
    'mysql_timestamp' => false
    ),
    'Orm\\Observer_Typing' => array(
    'events' => array('after_load', 'before_save', 'after_save')
    ),
    'Orm\\Observer_Self' => array(
    'events' => array('before_insert', 'before_update'),
    'property' => 'user_id'
    ),
    'Orm\\Observer_Slug' => array(
    'events' => array('before_insert'),
    'source' => 'username',
    'property' => 'slug'
    ),
    );
    }

    app/bootstrap.php:


    Autoloader::add_classes(array(
    'Model\\Auth_User' => APPPATH . 'classes/model/auth/user.php',
    ));
  • What are you exactly doing, in terms of using the model directly, or calling one of the Auth methods?
  • I'm adding the slug observer so that when a new user is added using the Auth::create_user method, a slug is automatically generated

  • Checked the Ormauth Auth drivers, and they all use \Model\Auth_User to access the users table. So I don't immediately see why this should not work.

    Can you add an _init() static method to your model, with a var_dump() or a die() in it, to see if it does get loaded at all?
  • Just did a quick test here.

    In app/classes/model/auth/user.php:
    <?php

    namespace Model;

    class Auth_User extends \Auth\Model\Auth_User
    {
        public static function _init()
        {
            die('loaded');
        }
    }
    and in the bootstrap:
    Autoloader::add_classes(array(
        'Model\Auth_User'            => APPPATH.'classes/model/auth/user.php',
    ));

    And this terminates with "loaded" without problems...
  • odd. it just refuses to add a slug to the slug column....

    Edit: I've managed to get slugs to work but I had to create a new driver altogether that in effect is a carbon copy of OrmAuth but because of this, OpAuth now no longer works.
  • I used this, and it generates the slug just fine:
    <?php

    namespace Model;

    class Auth_User extends \Auth\Model\Auth_User
    {
        public static function _init()
        {
            static::$_observers['Orm\\Observer_Slug'] = array(
                'events' => array('before_insert'),
                'source' => 'username',
                'property' => 'slug'
            );

            parent::_init();
        }
    }
  • i've used that exact same bit of code and it does nothing for me... it's being loaded because i did that test you posted above but for some reason the observer is being ignored.
  • Odd. I have no explanation for it. Time to debug the ORM model and/or the observer?
  • How do I go about that? Read the documentation but i'm no closer to finding out how to debug the observers
  • Go in the code of the observer and add some debug code. See if it's called, and what it does.

Howdy, Stranger!

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

In this Discussion