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


PHP EMongoDocument::model方法代码示例

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


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

示例1: __construct

 /**
  * Constructor.
  * @param mixed $modelClass the model class (e.g. 'Post') or the model finder instance
  * (e.g. <code>Post::model()</code>, <code>Post::model()->published()</code>).
  * @param array $config configuration (name=>value) to be applied as the initial property values of this class.
  * @since v1.0
  */
 public function __construct($modelClass, $config = array())
 {
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = EMongoDocument::model($modelClass);
     } else {
         if ($modelClass instanceof EMongoDocument) {
             $this->modelClass = get_class($modelClass);
             $this->model = $modelClass;
         } else {
             throw new EMongoException('Invalid model type for ' . __CLASS__);
         }
     }
     $this->_criteria = $this->model->getDbCriteria();
     if (isset($config['criteria'])) {
         $this->_criteria->mergeWith($config['criteria']);
         unset($config['criteria']);
     }
     $this->setId($this->modelClass);
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
     if ($this->keyField !== null && is_array($this->keyField)) {
         throw new EMongoException('This DataProvider cannot handle multi-field primary key.');
     } else {
         $this->keyField = '_id';
     }
 }
开发者ID:phiphi1992,项目名称:alongaydep,代码行数:35,代码来源:EMongoDocumentDataProvider.php

示例2: __construct

 /**
  * The cursor constructor
  * @param string|EMongoDocument $modelClass - The class name for the active record
  * @param array|MongoCursor|EMongoCriteria $criteria -  Either a condition array (without sort,limit and skip) or a MongoCursor Object
  * @param array $fields
  */
 public function __construct($modelClass, $criteria = array(), $fields = array())
 {
     // If $fields has something in it
     if (!empty($fields)) {
         $this->partial = true;
     }
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = EMongoDocument::model($this->modelClass);
     } elseif ($modelClass instanceof EMongoDocument) {
         $this->modelClass = get_class($modelClass);
         $this->model = $modelClass;
     }
     if ($criteria instanceof MongoCursor) {
         $this->cursor = $criteria;
         $this->cursor->reset();
     } elseif ($criteria instanceof EMongoCriteria) {
         $this->criteria = $criteria;
         $this->cursor = $this->model->getCollection()->find($criteria->condition, $criteria->project)->sort($criteria->sort);
         if ($criteria->skip > 0) {
             $this->cursor->skip($criteria->skip);
         }
         if ($criteria->limit > 0) {
             $this->cursor->limit($criteria->limit);
         }
     } else {
         // Then we are doing an active query
         $this->criteria = $criteria;
         $this->cursor = $this->model->getCollection()->find($criteria, $fields);
     }
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:37,代码来源:EMongoCursor.php

示例3: __construct

 /**
  * The cursor constructor
  * @param string|EMongoDocument $modelClass - The class name for the active record
  * @param array|MongoCursor|EMongoCriteria $criteria -  Either a condition array (without sort,limit and skip) or a MongoCursor Object
  * @param array $fields
  */
 public function __construct($model, $criteria = [], $fields = [])
 {
     if (is_string($model)) {
         $this->model = EMongoDocument::model($this->modelClass);
     } elseif ($model instanceof EMongoDocument) {
         $this->model = $model;
     }
     $this->options = [];
     if ($criteria instanceof EMongoCriteria) {
         $this->options['projection'] = $criteria->project;
         if ($criteria->skip > 0) {
             $this->options['skip'] = $criteria->skip;
         }
         if ($criteria->limit > 0) {
             $this->options['limit'] = intval($criteria->limit);
         }
         if ($criteria->sort) {
             $this->options['sort'] = $criteria->sort;
         }
         $this->query = $criteria->condition;
     } else {
         // Then we are doing an active query
         $this->options['projection'] = $fields;
         $this->query = $criteria;
     }
 }
开发者ID:yiicod,项目名称:mongoyii,代码行数:32,代码来源:EMongoQueryBuilder.php

示例4: __construct

 /**
  * Creates the EMongoDataProvider instance
  * @param string|EMongoDocument $modelClass
  * @param array $config
  */
 public function __construct($modelClass, $config = array())
 {
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = EMongoDocument::model($this->modelClass);
     } elseif ($modelClass instanceof EMongoDocument) {
         $this->modelClass = get_class($modelClass);
         $this->model = $modelClass;
     }
     $this->setId($this->modelClass);
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:19,代码来源:EMongoDataProvider.php

示例5: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     $className = $this->className === null ? get_class($object) : Yii::import($this->className);
     $attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
     $finder = EMongoDocument::model($className);
     $criteria = array($attributeName => $this->mongoId ? new MongoId($value) : $value);
     if (!$finder->exists($criteria)) {
         $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.');
         $this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value)));
     }
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:21,代码来源:EMongoExistValidator.php

示例6: resolveLabel

 /**
  * @see CSort::resolveLabel()
  * @param string $attribute
  * @return string
  */
 public function resolveLabel($attribute)
 {
     $definition = $this->resolveAttribute($attribute);
     if (is_array($definition)) {
         if (isset($definition['label'])) {
             return $definition['label'];
         }
     } elseif (is_string($definition)) {
         $attribute = $definition;
     }
     if ($this->modelClass !== null) {
         return EMongoDocument::model($this->modelClass)->getAttributeLabel($attribute);
     }
     return $attribute;
 }
开发者ID:yiicod,项目名称:mongoyii,代码行数:20,代码来源:EMongoSort.php

示例7: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     $className = $this->className === null ? get_class($object) : Yii::import($this->className);
     $attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
     // We get a RAW document here to prevent the need to make yet another active record instance
     $doc = EMongoDocument::model($className)->getCollection()->findOne(array_merge($this->criteria, [$attributeName => $this->caseSensitive ? $value : ['$regex' => $value, '$options' => 'i']]));
     // If a doc was fund and it isn't this doc, as decided by the primnary key
     if ($doc && (string) $doc[$object->primaryKey()] != (string) $object->getPrimaryKey()) {
         // Then it ain't unique
         $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
         $this->addError($object, $attribute, $message, ['{value}' => CHtml::encode($value)]);
     } else {
     }
 }
开发者ID:yiicod,项目名称:mongoyii,代码行数:24,代码来源:EMongoUniqueValidator.php

示例8: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     $className = $this->className === null ? get_class($object) : Yii::import($this->className);
     $attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
     // We get a RAW document here to prevent the need to make yet another active record instance
     $doc = EMongoDocument::model($className)->getCollection()->findOne(array_merge($this->criteria, array($attributeName => $this->caseSensitive ? $value : new MongoRegex('/' . $value . '/i'))));
     // If a doc was found first test if the unique attribute is the primaryKey
     // If we are uniquely id'ing the pk then check this is a new record and not
     // an old one and check to see if the pks are the same
     // If the found doc is not evaledd onm pk then make sure the two pks are not the same
     if ($doc && ($attributeName === $object->primaryKey() && $object->getIsNewRecord() && (string) $doc[$object->primaryKey()] == (string) $object->getPrimaryKey() || (string) $doc[$object->primaryKey()] != (string) $object->getPrimaryKey())) {
         // Then it ain't unique
         $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
         $this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value)));
     } else {
     }
 }
开发者ID:koma136,项目名称:mongoyii,代码行数:27,代码来源:EMongoUniqueValidator.php

示例9: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     $className = $this->className === null ? get_class($object) : Yii::import($this->className);
     $attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
     $finder = EMongoDocument::model($className);
     $criteria = new EMongoCriteria();
     $criteria->{$attribute} = $value;
     if ($this->criteria !== array()) {
         $criteria->mergeWith($this->criteria);
     }
     if (!$object instanceof EMongoDocument || $object->isNewRecord) {
         $exists = $finder->exists($criteria);
     } else {
         $criteria->limit = 2;
         $objects = $finder->findAll($criteria);
         $n = count($objects);
         if ($n === 1) {
             if ($column->isPrimaryKey) {
                 // primary key is modified and not unique
                 $exists = $object->getOldPrimaryKey() != $object->getPrimaryKey();
             } else {
                 // non-primary key, need to exclude the current record based on PK
                 $exists = $objects[0]->getPrimaryKey() != $object->getOldPrimaryKey();
             }
         } else {
             $exists = $n > 1;
         }
     }
     if ($exists) {
         $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
         $this->addError($object, $attribute, $message, array('{value}' => $value));
     }
 }
开发者ID:phiphi1992,项目名称:alongaydep,代码行数:43,代码来源:CMongoUniqueValidator.php

示例10: model

 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
开发者ID:phuongitvn,项目名称:vdh,代码行数:4,代码来源:BaseGenreModel.php

示例11: actionGetRequestInfo

 public function actionGetRequestInfo($className, $keyName, $key)
 {
     $requestModel = EMongoDocument::model($className)->findByAttributes(array($keyName => $key));
     $retArr = array();
     $widget = new CTextHighlighter();
     $widget->language = 'xml';
     $retArr['methodName'] = $requestModel->methodName;
     $retArr['requestXml'] = $widget->highlight($requestModel->requestXml);
     $retArr['responseXml'] = $widget->highlight($requestModel->responseXml);
     //$retArr['requestUrl'] = $requestModel->requestUrl;
     $retArr['timestamp'] = date("Y-m-d H:i:s", $requestModel->timestamp);
     $retArr['executionTime'] = Yii::app()->format->formatNumber($requestModel->executionTime);
     $retArr['errorDescription'] = $requestModel->errorDescription;
     echo json_encode($retArr);
     die;
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:16,代码来源:WorkflowStatesController.php

示例12: getRecord

 /**
  * Returns the specified EMongoDocument instance in the fixture data.
  * @param string $name the fixture name
  * @param string $alias the alias for the fixture data document
  * @return EMongoDocument the MongoDocument instance. False is returned
  * if there is no such fixture document.
  */
 public function getRecord($name, $alias)
 {
     if (isset($this->_records[$name][$alias])) {
         if (is_string($this->_records[$name][$alias])) {
             $row = $this->_rows[$name][$alias];
             $model = EMongoDocument::model($this->_records[$name][$alias]);
             $pk = $row['_id'];
             $this->_records[$name][$alias] = $model->findByPk($pk);
         }
         return $this->_records[$name][$alias];
     } else {
         return false;
     }
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:21,代码来源:EMongoDbFixtureManager.php

示例13: model

 /**
  * @param string $className
  * @return static
  */
 public static function model($className = '')
 {
     return parent::model($className ?: get_called_class());
 }
开发者ID:bangkok,项目名称:CodeExample,代码行数:8,代码来源:MtBaseMongoModel.php

示例14: getAttributeLabel

 /**
  * Returns the text label for the specified attribute.
  * This method overrides the parent implementation by supporting
  * returning the label defined in relational object.
  * In particular, if the attribute name is in the form of "post.author.name",
  * then this method will derive the label from the "author" relation's "name" attribute.
  * @see CModel::generateAttributeLabel()
  * @param string $attribute - the attribute name
  * @return string - the attribute label
  */
 public function getAttributeLabel($attribute)
 {
     $labels = $this->attributeLabels();
     if (isset($labels[$attribute])) {
         return $labels[$attribute];
     }
     if (strpos($attribute, '.') === false) {
         return $this->generateAttributeLabel($attribute);
     }
     $segs = explode('.', $attribute);
     $name = array_pop($segs);
     $model = $this;
     foreach ($segs as $seg) {
         $relations = $model->relations();
         if (!isset($relations[$seg])) {
             break;
         }
         $model = EMongoDocument::model($relations[$seg][1]);
     }
     return $model->getAttributeLabel($name);
 }
开发者ID:pvassiliou,项目名称:MongoYii,代码行数:31,代码来源:EMongoDocument.php


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