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


PHP ModelBehavior::beforeFind方法代码示例

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


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

示例1: beforeFind

 /**
  * beforeFind callback
  * 
  * @param object $Model
  * @param array $query
  */
 public function beforeFind(Model $Model, $query)
 {
     $Model->bindModel(array('hasOne' => array('Alias' => array('className' => 'Alias', 'foreignKey' => 'value', 'dependent' => true, 'conditions' => array('Alias.controller' => Inflector::tableize($Model->name)), 'fields' => '', 'order' => 'Alias.modified DESC'))), false);
     $query['contain'][] = 'Alias';
     $query['group'] = !empty($query['group']) ? $query['group'] : array($Model->alias => 'id');
     return parent::beforeFind($Model, $query);
 }
开发者ID:ajayphp,项目名称:Zuha,代码行数:13,代码来源:OptimizableBehavior.php

示例2: beforeFind

 /**
  * Before find we need to convert date fields to sqlformat
  *
  * @todo   Optimize cycle, really poor implementation here
  * @return Array
  **/
 public function beforeFind(Model $model, $query = array())
 {
     parent::beforeFind($model, $query);
     if ($model->findQueryType == 'count') {
         return $query;
     }
     //-- if conditions exists
     if (isset($query['conditions']) && is_array($query['conditions'])) {
         $columnTypes = $model->getColumnTypes();
         $fields = array_filter($columnTypes, array($this, 'valueIsDate'));
         //-- Get all conditions keys
         $conditionsKeys = array_keys($query['conditions']);
         $walked = array();
         foreach ($conditionsKeys as $conKey) {
             $cond = explode(' ', $conKey);
             if (!in_array($cond[0], $fields)) {
                 continue;
             }
             $curObj = $this->dateObject($query['conditions'][$conKey]);
             $walked[$conKey] = $this->ObjectToSQL($curObj);
         }
         $query['conditions'] = array_merge($query['conditions'], $walked);
     }
     return $query;
 }
开发者ID:raponiwalter,项目名称:Autodate,代码行数:31,代码来源:AutodateBehavior.php

示例3: beforeFind

/**
 * beforeFind method
 *
 * @param Model $model
 * @param array $query
 * @return void
 */
	public function beforeFind(Model $model, $query) {
		$settings = $this->settings[$model->alias];
		if (!isset($settings['beforeFind']) || $settings['beforeFind'] === 'off') {
			return parent::beforeFind($model, $query);
		}
		switch ($settings['beforeFind']) {
			case 'on':
				return false;
			case 'test':
				return null;
			case 'modify':
				$query['fields'] = array($model->alias . '.id', $model->alias . '.name', $model->alias . '.mytime');
				$query['recursive'] = -1;
				return $query;
		}
	}
开发者ID:hungnt88,项目名称:5stars-1,代码行数:23,代码来源:BehaviorCollectionTest.php

示例4: beforeFind

 /**
  * Before find callback
  *
  * @param object $model Model using this behavior
  * @param array $query Data used to execute this query, i.e. conditions, order, etc.
  * @return bool True if the operation should continue, false if it should abort
  */
 public function beforeFind($model, $query)
 {
     $result = parent::beforeFind($model, $query);
     if (empty($this->settings[$model->alias]['find']) || isset($query['defaultable']) && $query['defaultable'] === false || $result === false) {
         return $result;
     } else {
         if (is_array($result)) {
             $query = $result;
         }
     }
     $Db = ConnectionManager::getDataSource($model->useDbConfig);
     $defaultConditions = array();
     foreach ($this->settings[$model->alias]['find'] as $field => $fieldValue) {
         $fields = array($Db->name($model->alias) . '.' . $Db->name($field), $Db->name($field), $model->alias . '.' . $field, $field);
         $include = true;
         if (!empty($query['conditions'])) {
             foreach (Set::flatten((array) $query['conditions']) as $key => $value) {
                 $condition = is_numeric($key) ? $value : $key;
                 foreach ($fields as $field) {
                     if (preg_match('/^((not|or)\\.)?' . preg_quote($field) . '/i', $condition) || preg_match('/^((not|or)\\.)?' . preg_quote($model->alias . '.' . $field) . '/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($field) . '[^A-Z0-9_]+/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($model->alias . '.' . $field) . '[^A-Z0-9_]+/i', $condition)) {
                         $include = false;
                         break;
                     }
                 }
                 if (!$include) {
                     break;
                 }
             }
         }
         if ($include) {
             $defaultConditions[$model->alias . '.' . $field] = $fieldValue;
         }
     }
     if (!empty($defaultConditions)) {
         if (empty($query['conditions'])) {
             $query['conditions'] = array();
         } else {
             if (!is_array($query['conditions'])) {
                 $query['conditions'] = (array) $query['conditions'];
             }
         }
         $query['conditions'] = array_merge($query['conditions'], $defaultConditions);
         $result = $query;
     }
     return $result;
 }
开发者ID:rchick,项目名称:syrup,代码行数:53,代码来源:defaultable.php

示例5: beforeFind

 /**
  * Before find we need to convert date fields to sqlformat
  *
  * @todo   Optimize cycle, really poor implementation here
  * @todo   fix containable behavior
  * @return Array
  **/
 public function beforeFind(Model $model, $query = array())
 {
     parent::beforeFind($model, $query);
     if ($model->findQueryType == 'count') {
         return $query;
     }
     //-- if conditions exists
     if (isset($query['conditions']) && is_array($query['conditions'])) {
         $columnTypes = $model->getColumnTypes();
         $fields = array_filter($columnTypes, array($this, 'valueIsDate'));
         //-- Get all conditions keys
         $conditionsKeys = array_keys($query['conditions']);
         $walked = array();
         foreach ($conditionsKeys as $conKey) {
             $cond = explode(' ', $conKey);
             $cond[0] = str_replace($model->name . '.', null, $cond[0]);
             if (!array_key_exists($cond[0], $fields)) {
                 continue;
             }
             $values = $query['conditions'][$conKey];
             if (is_array($values)) {
                 foreach ($values as $key => $date) {
                     $tmpdate = $this->dateObject($date);
                     $query['conditions'][$conKey][$key] = $this->ObjectToSQL($tmpdate);
                 }
                 $walked[$conKey] = $query['conditions'][$conKey];
             } elseif (is_string($values)) {
                 $curObj = $this->dateObject($values);
                 if (!$curObj) {
                     continue;
                 }
                 $walked[$conKey] = $this->ObjectToSQL($curObj);
             }
         }
         $query['conditions'] = array_merge($query['conditions'], $walked);
     }
     return $query;
 }
开发者ID:cakephp-tutorial,项目名称:autodate,代码行数:45,代码来源:AutodateBehavior.php

示例6: beforeFind

 public function beforeFind(\Model $model, $query)
 {
     return parent::beforeFind($model, $query);
 }
开发者ID:jgprolluxer,项目名称:prosales,代码行数:4,代码来源:AppmenuBehavior.php

示例7: beforeFind

 /**
  * Adiciona condição de registros ativos nas buscas do modelo
  * @param Model $Model
  * @param array $queryData
  * @see ModelBehavior::beforeFind()
  */
 public function beforeFind(Model $Model, $queryData)
 {
     parent::beforeFind($Model, $queryData);
     $this->_prepareFind($queryData, $Model);
     return $queryData;
 }
开发者ID:radig,项目名称:SoftDelete,代码行数:12,代码来源:SoftDeleteBehavior.php

示例8: beforeFind

 /**
  *
  * @see ModelBehavior::beforeFind()
  */
 public function beforeFind(Model $model, $query)
 {
     parent::beforeFind($model, $query);
     $this->_Model = $model;
     $this->__checkConfig($model);
     $this->localizeData($query['conditions']);
     return $query;
 }
开发者ID:radig,项目名称:locale,代码行数:12,代码来源:LocaleBehavior.php

示例9: beforeFind

	/**
	 * Trim das informações no callback beforeFind
	 *
	 * @see ModelBehavior::beforeFind()
	 */
	public function beforeFind(Model $model, $query)
	{
		parent::beforeFind($model, $query);

		$this->_Model = $model;

		if (!isset($this->_disabledFor[$model->alias])) {
			$this->_autoTrim($query['conditions']);
		}

		$this->_autoTrim();

		return $query;
	}
开发者ID:radig,项目名称:user_guard,代码行数:19,代码来源:AutoTrimBehavior.php


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