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


PHP Criteria::setModelName方法代码示例

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


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

示例1: query

 /**
  * Create a criteria for a specific model
  *
  * @param \Phalcon\DiInterface|null $dependencyInjector
  * @return \Phalcon\Mvc\Model\Criteria
  */
 public static function query($dependencyInjector = null)
 {
     if (is_object($dependencyInjector) === false || $dependencyInjector instanceof DiInterface === false) {
         $dependencyInjector = DI::getDefault();
     }
     $criteria = new Criteria();
     $criteria->setDi($dependencyInjector);
     $criteria->setModelName(get_called_class());
     return $criteria;
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:16,代码来源:Model.php

示例2: newCriteria

 /**
  * @param array $data
  * @param string $operator
  * @return \Phalcon\Mvc\Model\Criteria
  */
 protected function newCriteria()
 {
     if (!$this->modelname) {
         throw new Exception('No valid model has been set');
     }
     $criteria = new Criteria();
     $criteria->setModelName($this->modelname)->setDI($this->getDI());
     return $criteria;
 }
开发者ID:logikostech,项目名称:forms,代码行数:14,代码来源:SelectOptions.php

示例3: fromInput

 /**
  * Builds a \Phalcon\Mvc\Model\Criteria based on an input array like $_POST
  *
  * @param \Phalcon\DiInterface $dependencyInjector
  * @param string $modelName
  * @param array $data
  * @return \Phalcon\Mvc\Model\Criteria
  * @throws Exception
  */
 public static function fromInput($dependencyInjector, $modelName, $data)
 {
     if (is_object($dependencyInjector) === false || $dependencyInjector instanceof DiInterface === false) {
         throw new Exception('A dependency injector container is required to obtain the ORM services');
     }
     if (is_string($modelName) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_array($data) === false) {
         throw new Exception('Model data must be an Array');
     }
     if (empty($data) === false) {
         $conditions = array();
         $metaData = $dependencyInjector->getShared('modelsMetadata');
         $model = new $modelName();
         $dataTypes = $metaData->getDataTypes($model);
         $bind = array();
         //We look for attributes in the array passed as data
         foreach ($data as $field => $value) {
             if (isset($dataTypes[$field]) === true && is_null($value) === false && $value !== '') {
                 if ($dataTypes[$field] === 2) {
                     //For varchar types we use LIKE operator
                     $condition = $field . ' LIKE :' . $field . ':';
                     $bind[$field] = '%' . $value . '%';
                 } else {
                     //For the rest of data types we use a plain = operator
                     $condition = $field . '=:' . $field . ':';
                     $bind[$field] = $value;
                 }
                 $conditions[] = $condition;
             }
         }
     }
     //Create an object instance and pass the parameters to it
     $criteria = new Criteria();
     if (isset($conditions) === true && empty($conditions) === false) {
         $criteria->where(implode(' AND ', $conditions));
         $criteria->bind($bind);
     }
     $criteria->setModelName($modelName);
     return $criteria;
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:51,代码来源:Criteria.php


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