本文整理汇总了PHP中AppModel::updateCounterCache方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::updateCounterCache方法的具体用法?PHP AppModel::updateCounterCache怎么用?PHP AppModel::updateCounterCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::updateCounterCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCounterCache
function updateCounterCache($keys = array(), $created = false)
{
parent::updateCounterCache($keys);
if (isset($this->data['Purchase'])) {
$this->log('Purchase::updateCounterCache');
$this->log(array_keys($this->data));
$cat_id = $this->data['Purchase']['category_id'];
$date = $this->data['Purchase']['date'];
// UPDATE MONTH TOTALS
$dts = strtotime($date);
$month = date('Y-m-01', $dts);
$dts = strtotime($month);
$next_month = date('Y-m-01', strtotime('+1 month', $dts));
$month_sum = $this->find('first', array('fields' => 'SUM(amount) as amount', 'conditions' => array("Purchase.date >= '{$month}'", "Purchase.date < '{$next_month}'", 'Purchase.category_id' => $cat_id)));
$month_sum = Set::extract($month_sum, 'Purchase.amount');
App::Import('Model', 'MonthTotal');
$m = new MonthTotal();
$data = array('MonthTotal' => array('id' => $month . '-' . $cat_id, 'date' => $month, 'category_id' => $cat_id, 'amount' => $month_sum));
$m->save($data);
// UPDATE YEAR TOTALS
$year = date('Y', strtotime($date)) . '-01-01';
$dts = strtotime($date);
$year = date('Y-01-01', $dts);
$dts = strtotime($year);
$next_year = date('Y-01-01', strtotime('+1 year', $dts));
$year_sum = $this->find('first', array('fields' => 'SUM(amount) as amount', 'conditions' => array("Purchase.date >= '{$year}'", "Purchase.date < '{$next_year}'", 'Purchase.category_id' => $cat_id)));
$year_sum = Set::extract($year_sum, 'Purchase.amount');
App::Import('Model', 'YearTotal');
$m = new YearTotal();
$data = array('YearTotal' => array('id' => $year . '-' . $cat_id, 'date' => $year, 'category_id' => $cat_id, 'amount' => $year_sum));
$m->save($data);
}
}
示例2: updateCounterCache
/**
* Counter cache should not happen when you are in ElasticSearch mode
*
* Updates the counter cache of belongsTo associations after a save or delete operation
*
* 'counterScope' defined get updated
*
* @param array $keys (optional) Optional foreign key data, defaults to the information $this->data
* @param boolean $created (optional) True if a new record was created, otherwise only associations with
* @return void
*/
public function updateCounterCache($keys = array(), $created = false)
{
if ($this->isElastic()) {
return;
}
return parent::updateCounterCache($keys, $created);
}