Skip to content

Commit abe1f59

Browse files
authored
Merge pull request #8228 from kenjis/docs-db-custom-object
docs: update sample code for Database Custom Result Objects
2 parents 502be28 + 63fc2c0 commit abe1f59

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

user_guide_src/source/database/results/003.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$query = $db->query('SELECT * FROM users;');
44

5-
foreach ($query->getResult('User') as $user) {
6-
echo $user->name; // access attributes
5+
foreach ($query->getResult(\App\Entities\User::class) as $user) {
6+
echo $user->name; // access attributes
77
echo $user->reverseName(); // or methods defined on the 'User' class
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$query = $db->query('SELECT * FROM users LIMIT 1;');
4-
$row = $query->getRow(0, 'User');
4+
$row = $query->getRow(0, \App\Entities\User::class);
55

6-
echo $row->name; // access attributes
6+
echo $row->name; // access attributes
77
echo $row->reverse_name(); // or methods defined on the 'User' class

user_guide_src/source/database/results/013.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
namespace App\Entities;
4+
35
class User
46
{
57
public $id;
68
public $email;
79
public $username;
810

9-
protected $last_login;
11+
protected $lastLogin;
1012

1113
public function lastLogin($format)
1214
{

user_guide_src/source/database/results/014.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
$query = $db->query('YOUR QUERY');
44

5-
$rows = $query->getCustomResultObject('User');
5+
$rows = $query->getCustomResultObject(\App\Entities\User::class);
66

77
foreach ($rows as $row) {
88
echo $row->id;
99
echo $row->email;
10-
echo $row->last_login('Y-m-d');
10+
echo $row->lastLogin('Y-m-d');
1111
}

user_guide_src/source/database/results/015.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
$query = $db->query('YOUR QUERY');
44

5-
$row = $query->getCustomRowObject(0, 'User');
5+
$row = $query->getCustomRowObject(0, \App\Entities\User::class);
66

77
if (isset($row)) {
8-
echo $row->email; // access attributes
9-
echo $row->last_login('Y-m-d'); // access class methods
8+
echo $row->email; // access attributes
9+
echo $row->lastLogin('Y-m-d'); // access class methods
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$row = $query->getCustomRowObject(0, 'User');
3+
$row = $query->getCustomRowObject(0, \App\Entities\User::class);

0 commit comments

Comments
 (0)