UnixTimestamp plugin for CakePHP
, (*1)
You can use this UnixTimestampBehavior insted of CakePHP's TimestampBehavior when want to save the unix timestamp, (*2)
Installation
You can install this plugin into your CakePHP application using composer., (*3)
The recommended way to install composer packages is:, (*4)
composer require oppara/cakephp-plugin-unix-timestamp
Enable plugin
You need to enable the plugin your config/bootstrap.php file:, (*5)
<?php
Plugin::load('Oppara/UnixTimestamp');
If you are already using Plugin::loadAll();
, then this is not necessary., (*6)
Usage
more info https://book.cakephp.org/3.0/en/orm/behaviors/timestamp.html, (*7)
CREATE TABLE users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created INT,
modified INT
);
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class UsersTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Oppara/UnixTimestamp.UnixTimestamp');
}
}