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


PHP xPDO::toCache方法代码示例

本文整理汇总了PHP中xPDO::toCache方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::toCache方法的具体用法?PHP xPDO::toCache怎么用?PHP xPDO::toCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xPDO的用法示例。


在下文中一共展示了xPDO::toCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: remove

 /**
  * Remove the persistent instance of an object permanently.
  *
  * Deletes the persistent object isntance stored in the database when
  * called, including any dependent objects defined by composite foreign key
  * relationships.
  *
  * @todo Implement some way to reassign ownership of related composite
  * objects when remove is called, perhaps by passing another object
  * instance as an optional parameter, or creating a separate method.
  *
  * @param array $ancestors Keeps track of classes which have already been
  * removed to prevent loop with circular references.
  * @return boolean Returns true on success, false on failure.
  */
 public function remove(array $ancestors = array())
 {
     $result = false;
     $pk = $this->getPrimaryKey();
     if ($pk && $this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
         if (!empty($this->_composites)) {
             $current = array($this->_class, $this->_alias);
             foreach ($this->_composites as $compositeAlias => $composite) {
                 if (in_array($compositeAlias, $ancestors) || in_array($composite['class'], $ancestors)) {
                     continue;
                 }
                 if ($composite['cardinality'] === 'many') {
                     if ($many = $this->getMany($compositeAlias)) {
                         foreach ($many as $one) {
                             $ancestors[] = $compositeAlias;
                             $newAncestors = $ancestors + $current;
                             if (!$one->remove($newAncestors)) {
                                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
                             }
                         }
                         unset($many);
                     }
                 } elseif ($one = $this->getOne($compositeAlias)) {
                     $ancestors[] = $compositeAlias;
                     $newAncestors = $ancestors + $current;
                     if (!$one->remove($newAncestors)) {
                         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
                     }
                     unset($one);
                 }
             }
         }
         $delete = $this->xpdo->newQuery($this->_class);
         $delete->command('DELETE');
         $delete->where($pk);
         // $delete->limit(1);
         $stmt = $delete->prepare();
         if (is_object($stmt)) {
             if (!($result = $stmt->execute())) {
                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true) . "\n" . print_r($stmt->errorInfo(), true));
             } else {
                 $callback = $this->getOption(xPDO::OPT_CALLBACK_ON_REMOVE);
                 if ($callback && is_callable($callback)) {
                     call_user_func($callback, array('className' => $this->_class, 'criteria' => $delete, 'object' => $this));
                 }
                 if ($this->xpdo->_cacheEnabled) {
                     $cacheKey = is_array($pk) ? implode('_', $pk) : $pk;
                     $this->xpdo->toCache($this->xpdo->getTableClass($this->_class) . '_' . $cacheKey, null, 0, array('modified' => true));
                 }
                 $this->xpdo->log(xPDO::LOG_LEVEL_INFO, "Removed {$this->_class} instance with primary key " . print_r($pk, true));
             }
         } else {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not build criteria to delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true));
         }
     }
     return $result;
 }
开发者ID:rosstimson,项目名称:revolution,代码行数:72,代码来源:xpdoobject.class.php

示例2: save


//.........这里部分代码省略.........
                     $where = '';
                     foreach ($pkn as $k => $v) {
                         $vt = PDO::PARAM_INT;
                         if (in_array($this->_fieldMeta[$k]['phptype'], array('string', 'float'))) {
                             $vt = PDO::PARAM_STR;
                         }
                         if ($iteration) {
                             $where .= " AND ";
                         }
                         $where .= $this->xpdo->escape($k) . " = :{$k}";
                         $bindings[":{$k}"]['value'] = $this->_fields[$k];
                         $bindings[":{$k}"]['type'] = $vt;
                         $iteration++;
                     }
                 } else {
                     $pkn = $this->getPK();
                     $pkt = PDO::PARAM_INT;
                     if (in_array($this->_fieldMeta[$pkn]['phptype'], array('string', 'float'))) {
                         $pkt = PDO::PARAM_STR;
                     }
                     $bindings[":{$pkn}"]['value'] = $pk;
                     $bindings[":{$pkn}"]['type'] = $pkt;
                     $where = $this->xpdo->escape($pkn) . ' = :' . $pkn;
                 }
                 if (!empty($updateSql)) {
                     $sql = "UPDATE {$this->_table} SET " . implode(',', $updateSql) . " WHERE {$where}";
                 }
             }
         }
         if (!empty($sql) && ($criteria = new xPDOCriteria($this->xpdo, $sql))) {
             if ($criteria->prepare()) {
                 if (!empty($bindings)) {
                     $criteria->bind($bindings, true, false);
                 }
                 if ($this->xpdo->getDebug() === true) {
                     $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Executing SQL:\n{$sql}\nwith bindings:\n" . print_r($bindings, true));
                 }
                 $tstart = microtime(true);
                 if (!($result = $criteria->stmt->execute())) {
                     $this->xpdo->queryTime += microtime(true) - $tstart;
                     $this->xpdo->executedQueries++;
                     $errorInfo = $criteria->stmt->errorInfo();
                     $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n" . $criteria->toSQL() . "\n" . print_r($errorInfo, true));
                     if (($errorInfo[1] == '1146' || $errorInfo[1] == '1') && $this->getOption(xPDO::OPT_AUTO_CREATE_TABLES)) {
                         if ($this->xpdo->getManager() && $this->xpdo->manager->createObjectContainer($this->_class) === true) {
                             $tstart = microtime(true);
                             if (!($result = $criteria->stmt->execute())) {
                                 $this->xpdo->queryTime += microtime(true) - $tstart;
                                 $this->xpdo->executedQueries++;
                                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n{$sql}\n");
                             } else {
                                 $this->xpdo->queryTime += microtime(true) - $tstart;
                                 $this->xpdo->executedQueries++;
                             }
                         } else {
                             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $this->xpdo->errorCode() . " attempting to create object container for class {$this->_class}:\n" . print_r($this->xpdo->errorInfo(), true));
                         }
                     }
                 } else {
                     $this->xpdo->queryTime += microtime(true) - $tstart;
                     $this->xpdo->executedQueries++;
                 }
             } else {
                 $result = false;
             }
             if ($result) {
                 if ($pkn && !$pk) {
                     if ($pkGenerated) {
                         $this->_fields[$this->getPK()] = $this->xpdo->lastInsertId();
                     }
                     $pk = $this->getPrimaryKey();
                 }
                 if ($pk || !$this->getPK()) {
                     $this->_dirty = array();
                     $this->_validated = array();
                     $this->_new = false;
                 }
                 $callback = $this->getOption(xPDO::OPT_CALLBACK_ON_SAVE);
                 if ($callback && is_callable($callback)) {
                     call_user_func($callback, array('className' => $this->_class, 'criteria' => $criteria, 'object' => $this));
                 }
                 if ($this->xpdo->_cacheEnabled && $pk && ($cacheFlag || $cacheFlag === null && $this->_cacheFlag)) {
                     $cacheKey = $this->xpdo->newQuery($this->_class, $pk, $cacheFlag);
                     if (is_bool($cacheFlag)) {
                         $expires = 0;
                     } else {
                         $expires = intval($cacheFlag);
                     }
                     $this->xpdo->toCache($cacheKey, $this, $expires, array('modified' => true));
                 }
             }
         }
     }
     $this->_saveRelatedObjects();
     if ($result) {
         $this->_dirty = array();
         $this->_validated = array();
     }
     return $result;
 }
开发者ID:e-gob,项目名称:apps.gob.cl,代码行数:101,代码来源:xpdoobject.class.php


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