Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fusic/reincarnation
Use version 1.1.x for Cake3.3 and below
https://github.com/fusic/reincarnation
Last synced: about 1 month ago
JSON representation
Use version 1.1.x for Cake3.3 and below
- Host: GitHub
- URL: https://github.com/fusic/reincarnation
- Owner: fusic
- License: mit
- Created: 2015-09-04T07:01:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-16T07:25:35.000Z (about 1 year ago)
- Last Synced: 2024-11-05T02:46:29.854Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 110 KB
- Stars: 3
- Watchers: 15
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Reincarnation
## Description
Soft delete plugin for CakePHP 5.x.
## Requirements
- PHP >= 8.1.*
- CakePHP >= 5.*## Installation
```
$ composer install
```# Usage
Create users table.
```sql
CREATE TABLE users
(
id serial NOT NULL,
username text,
password text,
created timestamp without time zone,
modified timestamp without time zone,
delete_flg boolean DEFAULT false,
deleted timestamp with time zone,
CONSTRAINT users_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
```UsersTable.php
```php
class UsersTable extends Table
{
public function initialize(array $config)
{
// Case 1
// default
// table field name
// boolean:deleted
// timestamp:delete_date
$this->addBehavior('Reincarnation.SoftDelete');// Case 2
// field name custom
// table field name
// boolean:delete_flg
// timestamp:deleted
$this->addBehavior('Reincarnation.SoftDelete', ['boolean' => 'delete_flg', 'timestamp' => 'deleted']);// Case 3
// boolean only
// table field name
// boolean:delete_flg
// timestamp:none
$this->addBehavior('Reincarnation.SoftDelete', ['boolean' => 'delete_flg', 'timestamp' => false]);// Case 4
// timestamp only
// table field name
// boolean:none
// timestamp:deleted
$this->addBehavior('Reincarnation.SoftDelete', ['boolean' => false, 'timestamp' => 'deleted']);
}
}
```UsersController.php
```php
class UsersController extends AppController
{
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$user = $this->Users->get($id);
if ($this->Users->softDelete($user)) {
//第二引数がtrueの場合、Entityのassociate先もあわせて削除します
//if ($this->Users->softDelete($user, true)) {
$this->Flash->success(__('The data has been deleted.'));
} else {
$this->Flash->error(__('The data could not be deleted. Please, try again.'));
}
return $this->redirect('action' => 'index');
}
}
```