Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
$_to_array_exclude didn't exclude fields in query building
  • Hi,

    I'm trying to exclude some fields in my User model:

    class Model_User extends \Orm\Model
    {
    protected static $_properties = array(
    'id',
    'username',
    'password',
    'email',
    'activated',
    'level',
    'banned',
    'ban_reason',
    'new_password_key',
    'new_password_requested',
    'new_email',
    'new_email_key',
    'last_ip',
    'last_login',
    'created',
    'modified',
    'referral',
    );

    protected static $_to_array_exclude = array(
            'password',
            'activated',
            'level',
            'banned',
            'ban_reason',
            'new_password_key',
            'new_password_requested',
            'new_email',
    'new_email_key',
    'last_ip',
    'referral'
        );

    protected static $_observers = array(
    'Orm\Observer_CreatedAt' => array(
    'events' => array('before_insert'),
    'mysql_timestamp' => true,
    'property' => 'created',
    ),
    'Orm\Observer_UpdatedAt' => array(
    'events' => array('before_save'),
    'mysql_timestamp' => true,
    'property' => 'modified',
    ),
    );
    }

    But it seems doesn't work, this is what I called:

            $users = Model_User::find(2);
            $this->response($users, 200);

    All the fields still showing up. What could be wrong?
  • A to_array filter does exactly that, it filters on to_array(). It will still query all fields to make sure the object cache is complete.

    So use:

      $this->response($users->to_array(), 200);

Howdy, Stranger!

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

In this Discussion