mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge remote-tracking branch 'upstream/develop' into 4.5
Conflicts: psalm_autoload.php
This commit is contained in:
commit
fff435c550
@ -26,6 +26,7 @@ foreach ($helperDirs as $dir) {
|
|||||||
$dirs = [
|
$dirs = [
|
||||||
'tests/_support/Controllers',
|
'tests/_support/Controllers',
|
||||||
'tests/_support/_controller',
|
'tests/_support/_controller',
|
||||||
|
'tests/system/Config/fixtures',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($dirs as $dir) {
|
foreach ($dirs as $dir) {
|
||||||
|
@ -21,6 +21,8 @@ DBQuery
|
|||||||
This event is triggered whenever a new query has been run, whether successful or not. The only parameter is
|
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
|
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
|
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
|
.. literalinclude:: events/001.php
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// In app/Config/Events.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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
$query = $db->query('SELECT * FROM users;');
|
$query = $db->query('SELECT * FROM users;');
|
||||||
|
|
||||||
foreach ($query->getResult('User') as $user) {
|
foreach ($query->getResult(\App\Entities\User::class) as $user) {
|
||||||
echo $user->name; // access attributes
|
echo $user->name; // access attributes
|
||||||
echo $user->reverseName(); // or methods defined on the 'User' class
|
echo $user->reverseName(); // or methods defined on the 'User' class
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$query = $db->query('SELECT * FROM users LIMIT 1;');
|
$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
|
echo $row->reverse_name(); // or methods defined on the 'User' class
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities;
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
public $id;
|
public $id;
|
||||||
public $email;
|
public $email;
|
||||||
public $username;
|
public $username;
|
||||||
|
|
||||||
protected $last_login;
|
protected $lastLogin;
|
||||||
|
|
||||||
public function lastLogin($format)
|
public function lastLogin($format)
|
||||||
{
|
{
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
$query = $db->query('YOUR QUERY');
|
$query = $db->query('YOUR QUERY');
|
||||||
|
|
||||||
$rows = $query->getCustomResultObject('User');
|
$rows = $query->getCustomResultObject(\App\Entities\User::class);
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
echo $row->id;
|
echo $row->id;
|
||||||
echo $row->email;
|
echo $row->email;
|
||||||
echo $row->last_login('Y-m-d');
|
echo $row->lastLogin('Y-m-d');
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
$query = $db->query('YOUR QUERY');
|
$query = $db->query('YOUR QUERY');
|
||||||
|
|
||||||
$row = $query->getCustomRowObject(0, 'User');
|
$row = $query->getCustomRowObject(0, \App\Entities\User::class);
|
||||||
|
|
||||||
if (isset($row)) {
|
if (isset($row)) {
|
||||||
echo $row->email; // access attributes
|
echo $row->email; // access attributes
|
||||||
echo $row->last_login('Y-m-d'); // access class methods
|
echo $row->lastLogin('Y-m-d'); // access class methods
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$row = $query->getCustomRowObject(0, 'User');
|
$row = $query->getCustomRowObject(0, \App\Entities\User::class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user