1. Go to this page and download the library: Download romano83/cakephp3-draft 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/ */
romano83 / cakephp3-draft example snippets
Plugin::load('Romano83/cakephp3-draft');
Plugin::loadAll();
namespace MyApp\Model\Table;
use Cake\ORM\Table;
class PostsTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Romano83/Cakephp3Draft.Draft');
}
}
namespace MyApp\Model\Table;
use Cake\ORM\Table;
class PostsTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior(
'Romano83/Cakephp3Draft.Draft', [
'conditions' => [
'draft' => 1
]
]
);
}
}
public function add(){
$post = $this->Posts->newEntity();
if($this->request->is(['post', 'put'])){
// Do your stuff here...
}else{
$post->id = $this->Posts->getDraftId($this->Posts); // get the last draft Id or create new one if needed
}
}
// OR
public function add(){
$post = $this->Posts->newEntity();
if($this->request->is(['post', 'put'])){
// Do your stuff here...
}else{
$post->id = $this->Posts->getDraftId($this->Posts, ['user_id' => 2]); // Get a draft Id for a content belonging to user 2 (or create a new one)
}
}
$this->Posts->cleanDrafts($this->Posts);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.