Skip to content

Commit

Permalink
added registerLinkTag, registerMetaTag to seo controller, added acces…
Browse files Browse the repository at this point in the history
…s to View from SeoController, new version
  • Loading branch information
shershennm committed Jan 3, 2017
1 parent 2182459 commit b58d2f3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!'],
];
}
Expand Down
3 changes: 2 additions & 1 deletion Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}

Expand Down
25 changes: 25 additions & 0 deletions SeoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <meta> tag in current view
* @param array $options params for View::registerMetaTag method
*/
public function registerMetaTag($options)
{
return $this->view->registerMetaTag($options);
}

/**
* Register <link> 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));
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit b58d2f3

Please sign in to comment.