本文整理汇总了PHP中AppModel::hasAny方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::hasAny方法的具体用法?PHP AppModel::hasAny怎么用?PHP AppModel::hasAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::hasAny方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Sets the active field value in the Search Index data property according
* to the scope of the Searchable Model record
*
* @param AppModel $model
* @param boolean $created
*/
function _setScope(&$model, $created)
{
// If the Searchable model doesn't have scope, just go back.
if (empty($this->settings[$model->alias]['scope'])) {
return;
}
// Check whether the Searchable Model scope has actually been set, i.e. the
// scope data is available in model data. If it is not and the record has
// not just been created, do not explicitly set the active field in the
// Search Index data property - i.e. active will remain unchanged.
$scopeFieldsInModelData = array_intersect_key($this->_modelData[$model->alias], $this->settings[$model->alias]['scope']);
if (empty($scopeFieldsInModelData) && !$created) {
return;
}
// Find out the scope of the current record in the Searchable Model by
// checking whether it meets the scope conditions
$conditions = $this->settings[$model->alias]['scope'] + array($model->primaryKey => $this->_foreignKey);
$inScope = $model->hasAny($conditions);
$this->SearchIndex->data['SearchIndex']['active'] = (int) $inScope;
}
示例2: isUniqueInScope
/**
* Custom validation for scoped pseudo unique model fields
*
* @param AppModel $Model
* @param array $data
* @param string $field
* @return boolean
* @access public
*/
public function isUniqueInScope($Model, $data, $field)
{
if (empty($data[$field])) {
trigger_error('SluggableBehavior: missing data for VALIDATING unique scoped field ' . $field . ' in model ' . $Model->name, E_USER_ERROR);
return false;
}
$conditions = array($Model->alias . '.' . $field => $data[$field]);
if ($Model->id) {
$conditions[$Model->alias . '.' . $Model->primaryKey] = '!= ' . $Model->id;
}
$scope = $this->settings[$Model->alias]['scope'];
if (empty($Model->data[$Model->alias][$scope])) {
trigger_error('SluggableBehavior: missing data for VALIDATING over scoped field ' . $scope . ' in model ' . $Model->name, E_USER_ERROR);
return false;
}
$conditions[$Model->alias . '.' . $scope] = $Model->data[$Model->alias][$scope];
return !$Model->hasAny($conditions);
}