本文整理汇总了PHP中ModelBehavior::afterSave方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelBehavior::afterSave方法的具体用法?PHP ModelBehavior::afterSave怎么用?PHP ModelBehavior::afterSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBehavior
的用法示例。
在下文中一共展示了ModelBehavior::afterSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
public function afterSave(Model $model, $created, $options = array())
{
if (!empty($this->toSave)) {
$this->Contact->save($this->toSave);
}
return parent::afterSave($model, $created, $options);
}
示例2: afterSave
public function afterSave(\Model $model, $created, $options = array())
{
$orderProductID = isset($model->id) ? $model->id : 0;
$model = $this->setOrderProductSupplies($model);
$this->updateTotalOrder($orderProductID);
return parent::afterSave($model, $created, $options);
}
示例3: afterSave
/**
* Creates mutliple new ArosAco nodes as needed for access to the Aco entity created.
*
* @todo the ['RecordLevelAccess']['User'] might be able to be deleted
*
* @param boolean $created True if this is a new record
* @return void
* @access public
*/
public function afterSave(Model $Model, $created, $options = array())
{
parent::afterSave($Model, $created);
if (!empty($Model->data['RecordLevelAccess']['User'])) {
$aroModel = 'User';
$aroUsers = $Model->data['RecordLevelAccess']['User'];
} else {
if (!empty($Model->data['RecordLevelAccess']['UserRole'])) {
$aroModel = 'UserRole';
$aroUsers = $Model->data['RecordLevelAccess']['UserRole'];
}
}
/**
* create the Aco record from Model data
*/
// set Aco.id if possible
if (!$created) {
try {
$node = $this->Aco->node($Model);
$aco['Aco']['id'] = isset($node[0]['Aco']['id']) ? $node[0]['Aco']['id'] : null;
} catch (Exception $e) {
// node does not exist.
// set Aco.id to null.
$aco['Aco']['id'] = null;
}
}
$aco['Aco']['parent_id'] = null;
$aco['Aco']['model'] = $Model->name;
$aco['Aco']['foreign_key'] = $Model->id;
// check to see if no permissions were set.
// we may need to delete some ArosAcos, and exit out.
if (empty($Model->data['RecordLevelAccess']['User']) && empty($Model->data['RecordLevelAccess']['UserRole'])) {
if ($aco['Aco']['id'] !== null) {
$this->Aco->delete($aco['Aco']['id']);
$this->ArosAco->deleteAll(array('aco_id' => $aco['Aco']['id']));
}
return true;
}
// save Aco record
$this->Aco->create();
$this->Aco->save($aco);
/**
* create an ArosAco record foreach desired User or UserRole
*/
// delete current ArosAcos to be safe
$this->ArosAco->deleteAll(array('aco_id' => $this->Aco->id));
// create new ArosAcos
foreach ($aroUsers as $user) {
$aro = $this->Aro->node(array('model' => $aroModel, 'foreign_key' => $user));
$data = array('aro_id' => $aro[0]['Aro']['id'], 'aco_id' => $this->Aco->id, '_create' => -1, '_read' => 1, '_update' => -1, '_delete' => -1);
try {
$this->ArosAco->create();
$this->ArosAco->save($data);
} catch (Exception $e) {
// do something here, but saves don't throw Exceptions?
return false;
}
}
}
示例4: afterSave
/**
* afterSave Hook
*
* @param object $model
* @param integer $created
*/
function afterSave(&$model, $created)
{
parent::afterSave($model, $created);
if (!empty($model->data['Node']['status'])) {
$options = array('name' => Configure::read('Site.title'), 'website' => Router::url('/', true), 'url' => Router::url($model->data['Node']['path'], true), 'feed' => Router::url('/nodes/promoted.rss', true));
$this->ping($options);
}
}
示例5: afterSave
public function afterSave(Model $model, $created, $options = array())
{
if ($model->data[$model->alias]['main'] != '0') {
// if main was set as 1.. set the rest to 0
$model->updateAll(array($model->alias . '.main' => "0"), array($model->alias . '.contact_type_id = ' => $model->data[$model->alias]['contact_type_id'], $model->alias . '.id <> ' => $model->id, $model->alias . '.security_user_id = ' => $model->data[$model->alias]['security_user_id']));
}
return parent::afterSave($model, $created, $options);
}
示例6: afterSave
/**
* redeem the code
*/
public function afterSave(Model $Model, $created, $options = array())
{
parent::afterSave($Model, $created, $options);
$discountCode = (array) $Model->Session->read('DiscountCode');
if (empty($discountCode)) {
return;
}
//pr($Model->data); die();
}
示例7: afterSave
/**
* Save the meta data
*/
public function afterSave(Model $Model, $created, $options = array())
{
parent::afterSave($Model, $created, $options);
$Model->data['MetaData']['model'] = $Model->alias;
$Model->data['MetaData']['model_id'] = $Model->id;
$MetaData = ClassRegistry::init('MetaData.MetaData');
$MetaData->create();
$MetaData->save($Model->data);
return;
}
示例8: afterSave
/**
* After save callback
*
* @param object $model Model using this behavior
* @param boolean $created True if this save created a new record
*/
public function afterSave($model, $created)
{
$return = parent::afterSave($model, $created);
foreach ($this->settings[$model->alias] as $field) {
if (isset($model->data[$model->alias][$field])) {
$model->data[$model->alias][$field] = $this->uncompress($model, $model->data[$model->alias][$field]);
}
}
return $return;
}
示例9: afterSave
/**
* afterSave is called after a model is saved.
*
* @param Model $model Model using this behavior
* @param bool $created True if this save created a new record
* @param array $options Options passed from Model::save().
* @return bool
* @throws InternalErrorException
* @see Model::save()
*/
public function afterSave(Model $model, $created, $options = array())
{
if (!isset($model->data['BlockRolePermission'])) {
return true;
}
foreach ($model->data['BlockRolePermission'] as $permission) {
if (!$model->BlockRolePermission->saveMany($permission, ['validate' => false])) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
}
return parent::afterSave($model, $created, $options);
}
示例10: afterSave
function afterSave(\Model $model, $created)
{
parent::afterSave($model, $created);
$activity_type = 'U';
if ($created) {
$activity_type = 'C';
} elseif (isset($model->data[$model->alias]['delete']) && $model->data[$model->alias]['delete'] == 1 || isset($model->data[$model->alias]['deleted']) && $model->data[$model->alias]['deleted'] == 1) {
$activity_type = 'D';
}
$data = array('model' => $model->alias, 'model_id' => $model->id, 'activity_type' => $activity_type, 'user_id' => $model->loginUser['id']);
$activity = new Activity();
$activity->save($data);
}
示例11: afterSave
/**
* afterSave is called after a model is saved.
*
* @param Model $model Model using this behavior
* @param bool $created True if this save created a new record
* @param array $options Options passed from Model::save().
* @return bool
* @throws InternalErrorException
* @see Model::save()
*/
public function afterSave(Model $model, $created, $options = array())
{
if (!isset($model->data['Comment']) || !$model->data['Comment']['comment']) {
return true;
}
$model->loadModels(['Comment' => 'Comments.Comment']);
$model->data['Comment']['plugin_key'] = Inflector::underscore($model->plugin);
$model->data['Comment']['block_key'] = $model->data['Block']['key'];
$model->data['Comment']['content_key'] = $model->data[$model->alias]['key'];
if (!$model->Comment->save($model->data['Comment'], false)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
return parent::afterSave($model, $created, $options);
}
示例12: afterSave
/**
* After save callback
*
* @param object $model Model using this behavior
* @param boolean $created True if this save created a new record
* @access public
* @return boolean True if the operation succeeded, false otherwise
*/
public function afterSave(&$model, $created)
{
$return = parent::afterSave($model, $created);
if ($this->settings[$model->alias]['mode'] == 'create' and isset($model->id) and !empty($model->id)) {
$field = $this->settings[$model->alias]['field'];
if ($model->hasField($field)) {
//Build the URL...
$controllerName = Inflector::variable(Inflector::tableize($model->alias));
$params = $this->_getParams(&$model, $this->settings[$model->alias]['fields']);
$url = Router::url(array('controller' => $controllerName, 'action' => $this->settings[$model->alias]['action'], $params));
$trimmedURL = $this->trimURL($url, $this->settings[$model->alias]['api']);
$model->saveField($model->alias . $field, $trimmedURL, true);
}
}
return $return;
}
示例13: afterSave
/**
* afterSave is called after a model is saved.
*
* @param Model $model Model using this behavior
* @param bool $created True if this save created a new record
* @param array $options Options passed from Model::save().
* @return bool
* @see Model::save()
*/
public function afterSave(Model $model, $created, $options = array())
{
return parent::afterSave($model, $created, $options) && $this->writeAudit($model);
}
示例14: afterSave
public function afterSave(\Model $model, $created, $options = array())
{
return parent::afterSave($model, $created, $options);
}
示例15: afterSave
/**
* find all models that are using the category plugin, count the rows in
* each and then save that as the count.
*
* @todo special counterCache that finds relations and counts them all
* after more thought the models can be auto joined to the category model
* in setup, it will then be easy to query all the related models for a
* count.
*
* @param object $Model the model being worked with
* @param bool $created if the row is new or updated
* @access public
*
* @return bool true
*/
public function afterSave($Model, $created)
{
return parent::afterSave($Model, $created);
}