本文整理汇总了PHP中Sites::currentSite方法的典型用法代码示例。如果您正苦于以下问题:PHP Sites::currentSite方法的具体用法?PHP Sites::currentSite怎么用?PHP Sites::currentSite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sites
的用法示例。
在下文中一共展示了Sites::currentSite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
public function initialize(Controller $controller)
{
$this->controller = $controller;
if (1 == $controller->Auth->user('role_id') && isset($controller->params['admin'])) {
$Model =& $controller->{$controller->modelClass};
if ($Model->Behaviors->attached('SiteFilter')) {
$Model->Behaviors->SiteFilter->disableFilter($Model);
}
}
$site = Sites::currentSite();
}
示例2: initialize
public function initialize(Controller $controller, $settings = array())
{
if (1 == $controller->Auth->user('role_id') && isset($controller->params['admin'])) {
if ($controller->{$controller->modelClass}) {
$Model =& $controller->{$controller->modelClass};
if ($Model instanceof Model && $Model->useTable && $Model->Behaviors->attached('SiteFilter')) {
$Model->Behaviors->SiteFilter->disableFilter($Model);
}
}
}
$site = Sites::currentSite();
}
示例3: beforeFind
public function beforeFind(Model $model, $query)
{
if ($this->settings[$model->alias]['enabled'] === false) {
return $query;
}
$this->_setupRelationships($model, $this->settings[$model->alias]);
$site = Sites::currentSite();
$sites = array(Sites::ALL_SITES);
if ($site) {
$sites = array_unique(array(Sites::ALL_SITES, $site['Site']['id']));
}
$setting = Set::merge(array('relationship' => array(), 'joins' => array()), $this->settings[$model->alias]);
extract($setting);
if (!empty($joins)) {
foreach ($joins as $join => &$joinConfig) {
if (empty($joinConfig)) {
continue;
}
// link to Site model
$foreignKey = $joinConfig['alias'] . '.site_id';
if (empty($joinConfig['conditions'][$foreignKey])) {
$joinConfig['conditions'][$foreignKey] = $sites;
}
$foreignKey = $joinConfig['alias'] . '.' . Inflector::underscore($model->alias) . '_id';
$condition = "{$model->alias}.{$model->primaryKey} = {$foreignKey}";
if (!in_array($condition, $joinConfig['conditions'])) {
$joinConfig['conditions'][] = $condition;
}
}
}
if (!empty($query['joins'])) {
$joins = Set::merge($query['joins'], $joins);
}
if (!empty($relationship) && $this->settings[$model->alias]['filter']) {
$relation = key($relationship);
$foreignKey = $model->{$relation}['Site']['foreignKey'];
switch ($relation) {
case 'belongsTo':
$query['conditions'][$model->alias . '.' . $foreignKey] = $sites;
break;
case 'hasAndBelongsToMany':
default:
$with = $model->{$relation}['Site']['with'];
if (strpos($with, '.') !== false) {
list($pluginName, $with) = pluginSplit($with);
}
$joinModel = $model->{$with};
$ds = $joinModel->getDataSource();
$associationForeignKey = $model->{$relation}['Site']['associationForeignKey'];
$currentJoins = Set::extract('{n}.alias', $joins);
if (!empty($currentJoins) && in_array($joinModel->alias, $currentJoins)) {
break;
}
$joins[] = array('type' => 'LEFT', 'table' => $ds->fullTableName($joinModel, true, true), 'alias' => $joinModel->alias, 'conditions' => array("{$model->alias}.{$model->primaryKey} = {$joinModel->alias}.{$foreignKey}"));
if (is_string($query['conditions'])) {
$query['conditions'] = array($query['conditions'], $joinModel->alias . '.' . $associationForeignKey => $sites);
} else {
$query['conditions'][$joinModel->alias . '.' . $associationForeignKey] = $sites;
}
break;
}
}
$query['joins'] = $joins;
unset($query['recursive']);
return $query;
}