Skip to content

Commit

Permalink
Merge pull request #8228 from kenjis/docs-db-custom-object
Browse files Browse the repository at this point in the history
docs: update sample code for Database Custom Result Objects
  • Loading branch information
kenjis authored Nov 20, 2023
2 parents 502be28 + 63fc2c0 commit abe1f59
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions user_guide_src/source/database/results/003.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

foreach ($query->getResult('User') as $user) {
echo $user->name; // access attributes
foreach ($query->getResult(\App\Entities\User::class) as $user) {
echo $user->name; // access attributes
echo $user->reverseName(); // or methods defined on the 'User' class
}
4 changes: 2 additions & 2 deletions user_guide_src/source/database/results/007.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

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

echo $row->name; // access attributes
echo $row->name; // access attributes
echo $row->reverse_name(); // or methods defined on the 'User' class
4 changes: 3 additions & 1 deletion user_guide_src/source/database/results/013.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

namespace App\Entities;

class User
{
public $id;
public $email;
public $username;

protected $last_login;
protected $lastLogin;

public function lastLogin($format)
{
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/database/results/014.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

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

foreach ($rows as $row) {
echo $row->id;
echo $row->email;
echo $row->last_login('Y-m-d');
echo $row->lastLogin('Y-m-d');
}
6 changes: 3 additions & 3 deletions user_guide_src/source/database/results/015.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

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

if (isset($row)) {
echo $row->email; // access attributes
echo $row->last_login('Y-m-d'); // access class methods
echo $row->email; // access attributes
echo $row->lastLogin('Y-m-d'); // access class methods
}
2 changes: 1 addition & 1 deletion user_guide_src/source/database/results/016.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

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

0 comments on commit abe1f59

Please sign in to comment.