diff --git a/README.md b/README.md index 883a1e0..42c16c7 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,12 @@ class SiteController extends SeoController public function actionIndex($viewParams) { $this->title = 'Hello world!'; - + + $this->registerMetaTag(['name' => 'description', 'content' => 'Cool page!']); + $this->registerLinkTag([['rel' => 'next', 'href' => 'https://my-cool-page.lh/article/2']]); + return [ - ['name' => 'keywords', 'content' => $this->getKeywords()], // params for Html::tag('meta', '', $params) + ['name' => 'keywords', 'content' => $this->getKeywords()], // params for View::registerMetaTag() function ['name' => 'description', 'content' => 'Cool page!'], ]; } diff --git a/Seo.php b/Seo.php index 054509f..c8f1668 100644 --- a/Seo.php +++ b/Seo.php @@ -94,6 +94,7 @@ private function executeSeoControllerAction($viewEvent) if (method_exists($seoController, $actionMethod)) { $seoController->controller = $this->controller; + $seoController->view = $viewEvent->sender; $meta = $seoController->$actionMethod($viewEvent->params); @@ -128,7 +129,7 @@ private function buildTitle($title) public function addMeta($view, $metaArray) { foreach ($metaArray as $meta) { - $view->metaTags[] = Html::tag('meta', '', $meta); + $view->registerMetaTag($meta); } } diff --git a/SeoController.php b/SeoController.php index c6aca05..5ea6ab5 100644 --- a/SeoController.php +++ b/SeoController.php @@ -16,4 +16,29 @@ abstract class SeoController extends Object * @var $controller \yii\web\Controller Web Controller instance */ public $controller; + + /** + * @var $view \yii\web\View Controller View + */ + public $view; + + /** + * Register tag in current view + * @param array $options params for View::registerMetaTag method + */ + public function registerMetaTag($options) + { + return $this->view->registerMetaTag($options); + } + + /** + * Register tag in current view + * @param array $options params for View::registerLinkTag method + */ + public function registerLinkTag($options) + { + return $this->view->registerLinkTag(array_merge([ + 'type' => null, + ], $options)); + } } \ No newline at end of file diff --git a/composer.json b/composer.json index 01f2e27..e5e8ddd 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { "name": "shershennm/yii2-seo", "description": "Yii2 extension for simple generating keywords and description", - "version": "2.0.2", + "version": "2.0.3", "type": "yii2-extension", - "keywords": ["yii2", "seo", "keywords", "meta"], + "keywords": ["yii2", "seo", "keywords", "meta", "link"], "homepage": "https://github.com/shershennm/yii2-seo", "time": "2015-10-19", "license": "MIT",