Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:ostapetc/Yii-CMS-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nizsheanez committed Aug 21, 2012
2 parents 4210f31 + fcf0401 commit 9d077bb
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 9,822 deletions.
30 changes: 30 additions & 0 deletions protected/components/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,36 @@ protected function performAjaxValidation($model)
}
}

public function setMetaTags($modelOrConfig)
{
if ($modelOrConfig instanceof CActiveRecord)
{
$meta_tag = MetaTag::model()->findByAttributes(array(
'model_id' => get_class($modelOrConfig),
'object_id' => $modelOrConfig->getPrimaryKey()
));
if ($meta_tag)
{
$meta_tag = array(
'title' => $meta_tag->title,
'description' => $meta_tag->description,
'keywords' => $meta_tag->keywords
);
}
}
else
{
$meta_tag = $modelOrConfig;
}
foreach ((array)$meta_tag as $key => $val)
{
if (is_string($val))
{
Yii::app()->clientScript->registerMetaTag($val, $key);
}
}
}

/**
* Возвращает модель по атрибуту и удовлетворяющую скоупам,
* или выбрасывает 404
Expand Down
18 changes: 7 additions & 11 deletions protected/components/filters/MetaTagsFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?
class MetaTagsFilter extends CFilter
{
public $findAttribute = 'id';
public $getParam = 'id';

protected function preFilter($filterChain)
{
$controller = $filterChain->controller;
Expand All @@ -9,20 +12,13 @@ protected function preFilter($filterChain)
return true;
}

if ($id = Yii::app()->request->getParam("id"))
if ($val = Yii::app()->request->getParam($this->getParam))
{
$class = $controller->getModelClass();

$meta_tag = MetaTag::model()->findByAttributes(array(
'model_id' => $class,
'object_id' => $id
));

if ($meta_tag)
$model = CActiveRecord::model($class)->findByAttributes(array($this->findAttribute => $val));
if ($model)
{
$controller->meta_title = $meta_tag->title;
$controller->meta_keywords = $meta_tag->keywords;
$controller->meta_description = $meta_tag->description;
$controller->setMetaTags($model);
}
}
return true;
Expand Down
Loading

0 comments on commit 9d077bb

Please sign in to comment.