Mainly a behavior in the form of a plugin, that adds the ability to easily save draft versions of a record without editing the current version of a record. Used for things like editing blog posts or web pages, but saving changes which aren't ready for prime time just yet. Version 1
- Create a plugins folder called Drafts
- Put this plugin into that folder. (or git clone [email protected]:zuha/Drafts-Zuha-Cakephp-Plugin.git app/Plugin/Drafts)
# in your model
public $actsAs = array('Drafts.Draftable');
# in your view
echo $this->Form->input('Article.draft', array('value' => 1));
- In the model you want to use drafts with, attach the Drafts.Draftable Behavior
- The default settings should do most of the work, but if you need something custom change the settings during behavior attachment.
- When you save a record add a field called 'draft' and set it to 1. For example...
- Click save and instead of editing the article it will save a draft which you can then preview by going to the view and
# in your controller
public function beforeFilter() {
parent::beforeFilter();
if (!empty($this->request->params['named']['draft'])) {
$this->Article->Behaviors->attach('Drafts.Draftable', array(
'returnVersion' => $this->request->params['named']['draft'],
));
}
}
- In your controller add a beforeFilter method, similar to the above...
- Visit a url similar to http:https://example.com/articles/articles/view/3/draft:1
- It will return the results of the newest draft instead of the actual live version
- Visit a url similar to http:https://example/articles/articles/view/3/draft:4
- It will return the results of the fourth oldest draft instead of the actual live version
- If there are only 2 drafts, then it will return the oldest available instead of the fourth.
- triggerField ... Change the name of the field you send in a form from 'draft', to whatever you want.
- foreignKeyName ... If you want to hard code something other than 'id' as the primary key.
- reviseDateField ... unused as of 4/15/2012, meant to be for rolling back to older versions via post data.
- conditions ... Set conditions so that viewing a draft only works with a filtered subset of records. (ie. Article.type = public)
- returnVersion ... a setting to choose which version is returned during the find
- None
- PHP version: PHP 5.3+
- CakePHP version: 2.x Stable
For support and feature request, please visit submit an issue through Github.com.
For more information about our Professional Web Design, Development, and Marketing Services please visit the Zuha Development Corporation website.
Copyright 2009-2012, RazorIT LLC
Licensed under GPLv3 Redistributions of files must retain the below copyright notice.
Copyright 2009-2012 RazoIT LLC 8417 Oswego Rd. #121 Baldwinsville, NY 13027 http:https://razorit.com