Skip to content

Commit f844bdc

Browse files
authored
Added "Hidden Fields" documentation.
1 parent e0383fb commit f844bdc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

dbObject.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,42 @@ $products = product::arraybuilder()->paginate($page);
295295
echo "showing $page out of " . product::$totalPages;
296296

297297
```
298+
299+
###Hidden Fields
300+
Sometimes it's important to block some fields that can be accessed from outside the model class (for example, the user password).
301+
302+
To block the access to certain fields using the `->` operator, you can declare the `$hidden` array into the model class. This array holds column names that can't be accessed with the `->` operator.
303+
304+
For example:
305+
306+
```php
307+
class User extends dbObject {
308+
protected $dbFields = array(
309+
'username' => array('text', 'required'),
310+
'password' => array('text', 'required'),
311+
'is_admin' => array('bool'),
312+
'token' => array('text')
313+
);
314+
315+
protected $hidden = array(
316+
'password', 'token'
317+
);
318+
}
319+
```
320+
321+
If you try to:
322+
```php
323+
echo $user->password;
324+
echo $user->token;
325+
```
326+
327+
Will return `null`, and also:
328+
```php
329+
$user->password = "my-new-password";
330+
```
331+
332+
Won't change the current `password` value.
333+
298334
###Examples
299335

300336
Please look for a use examples in <a href='tests/dbObjectTests.php'>tests file</a> and test models inside the <a href='tests/models/'>test models</a> directory

0 commit comments

Comments
 (0)