Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel\Core\PhpErrorException [ Notice ]: unserialize(): Error at offset 5 of 60 bytes
  • Thanks Harro for your help.
  • Hi Harro,

    I am doing php oil refine migrate
    I am getting Already on the latest migration for app:default.

  • Hi Harro,

    I changed user model to class Model_User extends \Model\Auth_User
    deleted all tables and ran the migrate.
    I then did the conversion using create_user

    The profile fields are still serialized.
    What did I miss?

  • How do you use an observer?
  • I can't reproduce your problem. Test code:

            $user = \Model\Auth_User::find(7);
            var_dump($user);
            die();

    Output (as you can see, _data[profile_fields] has become an array):

    object(Auth\Model\Auth_User)[35]
      protected '_is_new' => boolean false
      protected '_frozen' => boolean false
      protected '_sanitization_enabled' => boolean false
      protected '_data' =>
        array (size=10)
          'id' => string '7' (length=1)
          'username' => string 'WanWizard' (length=9)
          'email' => string 'wanwizard@fuelphp.xxx' (length=21)
          'group' => string '50' (length=2)
          'password' => string 'nF0z+36kZ6qN8TEkqsfXLp5hoNtjtupcnBb0l/ixhDk=' (length=44)
          'profile_fields' =>
            array (size=3)
              'full_name' => string 'Harro Verton' (length=12)
              'timezone' => string 'Europe/London' (length=13)
              'dateformat' => string 'eu' (length=2)
          'last_login' => string '1360438873' (length=10)
          'login_hash' => string 'bfd71587f7b0071d4746fdadfdf5bf4c40b55122' (length=40)
          'created_at' => string '1330895272' (length=10)
          'updated_at' => null
      protected '_custom_data' =>
        array (size=0)
          empty
      protected '_original' =>
        array (size=10)
          'id' => string '7' (length=1)
          'username' => string 'WanWizard' (length=9)
          'email' => string 'wanwizard@fuelphp.xxx' (length=21)
          'group' => string '50' (length=2)
          'password' => string 'nF0z+36kZ6qN8TEkqsfXLp5hoNtjtupcnBb0l/ixhDk=' (length=44)
          'profile_fields' => string 'a:3:{s:9:"full_name";s:12:"Harro Verton";s:8:"timezone";s:13:"Europe/London";s:10:"dateformat";s:2:"eu";}' (length=107)
          'last_login' => string '1360438873' (length=10)
          'login_hash' => string 'bfd71587f7b0071d4746fdadfdf5bf4c40b55122' (length=40)
          'created_at' => string '1330895272' (length=10)
          'updated_at' => null
      protected '_data_relations' =>
        array (size=0)
          empty
      protected '_original_relations' =>
        array (size=0)
          empty
      protected '_reset_relations' =>
        array (size=0)
          empty
      protected '_disabled_events' =>
        array (size=0)
          empty
      protected '_view' => null
      protected '_iterable' =>
        array (size=0)
          empty

  • It works with Model_User::find('all');
    but not using Model_User::query();
  • $user = \Model\Auth_User::query()->where('id', '=', 7)->get_one();

    returns exactly the same. What is your exact query statement?
  • And your fuel/classes/model/user.php is now completely empty, except for

    <?php
    class Model_User extends \Model\Auth_User;

    or does it contain anything else?
  • Here is my model

    class Model_User extends \Auth\Model\Auth_User
    {
    protected static $_properties = array(
    'id',
    'username',
    'password',
    'group',
    'email',
    'last_login',
    'login_hash',
    'profile_fields',
    'created_at',
    'updated_at',
    );

    protected static $_observers = array(
    'Orm\Observer_CreatedAt' => array(
    'events' => array('before_insert'),
    'mysql_timestamp' => false,
    ),
    'Orm\Observer_UpdatedAt' => array(
    'events' => array('before_update'),
    'mysql_timestamp' => false,
    ),
    );

    protected static $_table_name = 'users';
        
        public static function validate($factory)
    {
    $val = Validation::forge($factory);
    $val->add_field('username', 'Username', 'required|unique');
    $val->add_field('email', 'Email', 'required|valid_email|unique');

    return $val;
    }
  • I tried adding to user model
    'Orm\Observer_Typing' => array(
    'events' => array('after_load', 'before_save', 'after_save'),
    ),
  • You still override the property definitions from the Auth model.

    So remove $_observers and $_properties. The are all defined in the parent class. The tablename, although not needed, and all methods can stay.
  • Thanks Harro, it works now.
    But what if I want to use an observer to set the date on insert or update?
    As soon as I add the observer to user model, the profile fields are back to being serialized.
  • If you need to add to a property that is defined in a parent class, use the _init() method. A complex example from one of our apps:

        /**
         * Model runtime initialisation
         */
        public static function _init()
        {
            // add te required observers
            static::$_observers['Orm\\Observer_CreatedAt'] = array('events' => array('before_insert'),'property' => 'created_at', 'mysql_timestamp' => false);
            static::$_observers['Orm\\Observer_UpdatedAt'] = array('events' => array('before_update'), 'property' => 'updated_at', 'mysql_timestamp' => false);
            if ( ! isset(static::$_observers['Orm\\Observer_Self']))
            {
                static::$_observers['Orm\\Observer_Self'] = array('events' => array('before_insert', 'before_update'), 'property' => 'user_id');
            }
            else
            {
                in_array('before_save', static::$_observers['Orm\\Observer_Self']['events']) or static::$_observers['Orm\\Observer_Self']['events'][] = array('before_insert', 'before_update');
            }
            static::$_observers['Orm\\Observer_Typing'] = array('events' => array('after_load', 'before_save', 'after_save'));

            // make sure required properties are defined
            isset(static::$_properties['user_id']) or static::$_properties['user_id'] = array('data_type' => 'int', 'default' => 0, 'null' => true, 'form' => array('type' => false));
            isset(static::$_properties['created']) or static::$_properties['created_at'] = array('data_type' => 'int', 'default' => 0, 'null' => true, 'form' => array('type' => false));
            isset(static::$_properties['updated']) or static::$_properties['updated_at'] = array('data_type' => 'int', 'default' => 0, 'null' => true, 'form' => array('type' => false));
        }

  • Wow, I guess that is complicated.
    Anyway, thank you so much for your help on this and taking the time to help me resolve it.

    Best Regards,

    Frank
  • You're welcome.

    It's something you've got to get to grips with I'm afraid, it's basic object oriented PHP, you'll encounter it more and more.

Howdy, Stranger!

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

In this Discussion