Here's the link to the hasField method I forgot to paste http://api.cakephp.org/2.4/class-Model.html#_hasField
So just to elaborate, in AppModel::beforeDelete() I check if the deleted field exists, if so I update the deleted field and return false. Otherwise I return true and let CakePHP do its thing.
On 26 July 2014 10:22, Stephen S <hellospeakman@gmail.com> wrote:
If you want to do this with a behavior then you should look at the beforeDelete callback, you can update your field within this callback and then return false to automatically abort the delete (as per the book).http://book.cakephp.org/2.0/en/models/behaviors.html#ModelBehavior::beforeDeleteYou could also just write something like this in your AppModel to make it apply to all models, my applications use $this->hasField('deleted') to see if soft delete is supported with the model.--On 26 July 2014 09:22, Sam Clauw <info@bellewaerdefun.be> wrote:
I'll try to write my very first behavior that does a soft delete instead of a hard delete. I've expanded my model with--public $actsAs = array('SoftDelete');and I've created the behavior "SoftDeleteBehavior.php" in App/Model/Behavior:<?php
App::uses('ModelBehavior', 'Model');
class SoftDeleteBehavior extends ModelBehavior
{
function setup(Model $Model, $settings = array())
{
}
function delete(Model $Model, $id = null)
{
$Model->id = $id;
if ($Model->saveField('deleted', date('Y-m-d H:i:s'))) {
return true;
}
return false;
}
}However, when I try to delete something, the delete() method from my behavior doesn't overwrite the normal one. What could cause this issue?
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Kind RegardsStephen Speakman
Kind Regards
Stephen Speakman
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment