本文整理汇总了PHP中ModelBehavior::beforeDelete方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelBehavior::beforeDelete方法的具体用法?PHP ModelBehavior::beforeDelete怎么用?PHP ModelBehavior::beforeDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBehavior
的用法示例。
在下文中一共展示了ModelBehavior::beforeDelete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDelete
/**
* Before delete is called before any delete occurs on the attached model, but after the model's
* beforeDelete is called. Returning false from a beforeDelete will abort the delete.
*
* @param Model $model Model using this behavior
* @param bool $cascade If true records that depend on this record will also be deleted
* @return mixed False if the operation should abort. Any other result will continue.
*/
public function beforeDelete(Model $model, $cascade = true)
{
if (!empty($model->hasMany['Audit'])) {
if ($model->id = !empty($model->id) ? $model->id : (!empty($model->data[$model->alias]['id']) ? $model->data[$model->alias]['id'] : '')) {
$record = $model->read(null);
$this->data[$model->id]['Audit']['entity'] = (!empty($model->plugin) ? $model->plugin . '.' : '') . $model->name;
$this->data[$model->id]['Audit']['entity_id'] = $model->id;
$this->data[$model->id]['Audit']['event'] = 'DELETE';
$this->data[$model->id]['Audit']['old'] = json_encode($record[$model->alias]);
$this->data[$model->id]['Audit']['new'] = json_encode(array());
$this->data[$model->id]['Audit']['creator_id'] = !empty($model->data['Creator']['id']) ? $model->data['Creator']['id'] : null;
$model->data = Hash::remove($model->data, 'Creator');
}
}
return parent::beforeDelete($model, $cascade);
}
示例2: beforeDelete
/**
* Before delete callback
*
* @param object $model
* @return void
*/
public function beforeDelete(Model $model, $cascade = true)
{
parent::beforeDelete($model, $cascade);
$model->bindModel(array('hasMany' => array('Nodeattachment' => array('order' => array('Nodeattachment.priority ASC', 'Nodeattachment.created ASC')))));
$data = $model->findById($model->id);
if (isset($data['Nodeattachment'])) {
App::import('Model', 'Nodeattachment.Nodeattachment');
$Nodeattachment = new Nodeattachment();
// delete all attachments for node
foreach ($data['Nodeattachment'] as $attachment) {
$Nodeattachment->read(null, $attachment['id']);
if (!$Nodeattachment->delete($attachment['id'])) {
return FALSE;
}
}
}
return true;
}
示例3: beforeDelete
/**
* beforeDelete method
*
* @param Model $model
* @param boolean $cascade
* @return void
*/
public function beforeDelete(Model $model, $cascade = true)
{
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] === 'off') {
return parent::beforeDelete($model, $cascade);
}
switch ($settings['beforeDelete']) {
case 'on':
return false;
case 'test':
return null;
case 'test2':
echo 'beforeDelete success';
if ($cascade) {
echo ' (cascading) ';
}
return true;
}
}
示例4: beforeDelete
public function beforeDelete(\Model $model, $cascade = true)
{
return parent::beforeDelete($model, $cascade);
}
示例5: beforeDelete
/**
* Called before every deletion operation.
*
* @param Model $model Model instance
* @param boolean $cascade If true records that depend on this record will also be deleted
* @return boolean True if the operation should continue, false if it should abort
*/
public function beforeDelete(Model $model, $cascade = true)
{
$data = $model->find('first', array('conditions' => array("{$model->alias}.{$model->primaryKey}" => $model->id), 'contain' => false, 'recursive' => -1));
foreach ($this->settings[$model->alias] as $field => $options) {
$this->_prepareFilesForDeletion($model, $field, $data, $options);
}
return parent::beforeDelete($model, $cascade);
}
示例6: beforeDelete
public function beforeDelete(\Model $model, $cascade = true)
{
parent::beforeDelete($model);
return true;
}
示例7: beforeDelete
/**
* Catch the request to delete and route to our own delete method
*
* // TODO: Try and remove this, as the controller should be calling the delete
* method in the model, which this should overwrite
*
* // TODO: Think about the return here as returning true will continue the
* delete and will probably be destructive
*
* @param Model $model
* @param bool $cascade
* @return bool
*/
public function beforeDelete(Model $model, $cascade = true)
{
parent::beforeDelete($model, $cascade);
$this->delete($model, $model->data[$model->alias]['id'], $cascade);
return false;
}
示例8: beforeDelete
/**
*
*
* @param Model $Model
* @param bool $cascade
*/
public function beforeDelete(Model $Model, $cascade = true)
{
parent::beforeDelete($Model, $cascade);
$this->takeSnapshot($Model);
return true;
}
示例9: beforeDelete
/**
* Called automatically before Model::delete()
*
* If deleting a record that has associated habtm records, the habtm records
* counter caches will need re-calculating, so identify them. E.g. get the
* tag_ids of the Tags that the Post being deleted was tagged with.
*
* @param AppModel $model
* @return boolean Always true
*/
public function beforeDelete(\Model $model, $cascade = true)
{
parent::beforeDelete($model, $cascade);
$this->_setOldHabtmIds($model);
return true;
}
示例10: beforeDelete
/**
* beforeDelete callback
*
* cleanup any related bitmask rows
*
* @param Model $Model
* @param boolean $cascade
* @return mixed
*/
public function beforeDelete(Model $Model, $cascade = true)
{
if ($this->settings[$Model->alias]['consolidated'] && !$this->settings[$Model->alias]['disabled'] && $cascade && !$Model->Behaviors->loaded('SoftDeletable')) {
$this->_bind($Model);
} else {
$this->_unbind($Model);
}
return parent::beforeDelete($Model, $cascade);
}