Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
 Conflicts:
	psalm_autoload.php
  • Loading branch information
kenjis committed Nov 20, 2023
2 parents 9954ccf + 45ce53b commit fff435c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions psalm_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$dirs = [
'tests/_support/Controllers',
'tests/_support/_controller',
'tests/system/Config/fixtures',
];

foreach ($dirs as $dir) {
Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/database/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ DBQuery
This event is triggered whenever a new query has been run, whether successful or not. The only parameter is
a :doc:`Query </database/queries>` instance of the current query. You could use this to display all queries
in STDOUT, or logging to a file, or even creating tools to do automatic query analysis to help you spot
potentially missing indexes, slow queries, etc. An example usage might be:
potentially missing indexes, slow queries, etc.

An example usage might be:

.. literalinclude:: events/001.php
16 changes: 15 additions & 1 deletion user_guide_src/source/database/events/001.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<?php

// In app/Config/Events.php
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');

namespace Config;

use CodeIgniter\Events\Events;
use CodeIgniter\Exceptions\FrameworkException;
use CodeIgniter\HotReloader\HotReloader;

// ...

Events::on(
'DBQuery',
static function (\CodeIgniter\Database\Query $query) {
log_message('info', (string) $query);
}
);
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 fff435c

Please sign in to comment.