当前位置: 首页>>代码示例>>PHP>>正文


PHP AppModel::updateCounterCache方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:02468,项目名称:ebocash,代码行数:33,代码来源:purchase.php

示例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);
 }
开发者ID:el-barto,项目名称:cakephp-elastic-search-datasource,代码行数:18,代码来源:ElasticAppModel.php


注:本文中的AppModel::updateCounterCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。