Skip to main content

ORM

CakePHP ORM and Logging Queries

·196 words·1 min
Working with cakephp/orm library, I needed to log all the queries. Cakephp provides a way to do it via cakephp/log. 1 2 3 4 5 6 7 8 9 <?php use Cake\Log\Log; Log::config('queries', [ 'className' => 'File', 'path' => '/my/log/path/', 'file' => 'app', 'scopes' => ['queriesLog'] ]); But you are not limited, if you need to configure it to a PSR-3 logger like monolog/monolog 1 2 3 4 5 6 7 8 9 10 <?php use Cake\Log\Log; use Monolog\Logger; use Monolog\Handler\StreamHandler; Log::config('default', function () { $log = new Logger('cli'); $log->pushHandler(new StreamHandler('php://stdout')); return $log; }); That was pretty simple and it logs to cli.

CakePHP ORM and Illuminate Pagination

·304 words·2 mins
Do you know CakePHP version 3 has a lovely ORM which can be used as standalone? Thank you José Lorenzo Rodríguez and every contributor, for your hard work. 1 composer require cakephp/orm That’s it. Working on I noticed I need to do some pagination. Oh, remember we have illuminate/pagination. Why not use it? Problem, there seems no one have implemented it. How could we achieve it? Lets do it. 1 composer require illuminate/pagination If you are using a psr-7 request / response here is the middleware for you.