PHP code example of mirko-pagliai / cakephp-entities-logger
1. Go to this page and download the library: Download mirko-pagliai/cakephp-entities-logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mirko-pagliai / cakephp-entities-logger example snippets
namespace App\Model\Table;
use Cake\ORM\Table;
class ArticlesTable extends Table
{
public function initialize(array $config): void
{
// ...
$this->addBehavior('Cake/EntitiesLogger.EntitiesLog');
// ...
}
}
$Article = $this->Articles->find()
->contain(['EntitiesLogs' => ['Users']])
->where(['Articles.id' => $id])
->firstOrFail();
foreach ($Article->entities_logs as $EntitiesLog) {
// `type` is a `Cake\EntitiesLogger\Model\Enum\EntitiesLogType` (`Created`, `Updated` or `Deleted`)
echo $EntitiesLog->type->name . ' by user ' . $EntitiesLog->user_id . ' on ' . $EntitiesLog->datetime;
}
namespace App\Model\Behavior;
use App\Model\Table\EntitiesLogsTable;
use Cake\EntitiesLogger\Model\Behavior\EntitiesLogBehavior as BaseEntitiesLogBehavior;
use Cake\ORM\Table;
class EntitiesLogBehavior extends BaseEntitiesLogBehavior
{
/**
* @inheritDoc
*/
public function __construct(Table $table, array $config = [])
{
$this->EntitiesLogsTable = $this->fetchTable(EntitiesLogsTable::class);
parent::__construct($table, $config);
}
}
$this->addBehavior('EntitiesLog');
namespace App\Model\Entity;
use Cake\EntitiesLogger\Model\Entity\EntitiesLog as BaseEntitiesLog;
class EntitiesLog extends BaseEntitiesLog
{
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.