Skip to content

Conversation

@Skazza94
Copy link
Contributor

@Skazza94 Skazza94 commented Feb 23, 2017

In current version, every column of a table mapped into a dbObject is accessible through the magic getter method and editable through magic setter method.

But sometimes it's important to hide some fields/columns from the model (for example, access user password with $user->password is not that good, as updating it with $user->password = "random").

I've added a $hidden array, that holds column names that can't be accessed with magic methods. This array must be declared into the model class, as the other arrays supported by the library.

class User extends dbObject {
    protected $dbFields = array(
        'username' => array('text', 'required'),
        'password' => array('text', 'required'),
        'is_admin' => array('bool'),
        'token' => array('text')
    );

    protected $hidden = array(
        'password', 'token'
    );
}

If you try to:

echo $user->password;
echo $user->token;

Will return null, and also:

$user->password = "my-new-password";

Won't change the current "password" value.

Added guard check at the beginning of the method, removed name === 'hidden' (that was useless).
@avbdr
Copy link
Collaborator

avbdr commented Mar 1, 2017

thats a good pull request. Can you please add new feature description in a readme?

@Skazza94
Copy link
Contributor Author

Skazza94 commented Mar 1, 2017

@avbdr Done, check it out! :)

@avbdr avbdr merged commit b654510 into ThingEngineer:master Mar 1, 2017
@Skazza94 Skazza94 deleted the patch-1 branch February 20, 2019 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants