PHP code example of shershennm / yii2-seo

1. Go to this page and download the library: Download shershennm/yii2-seo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shershennm / yii2-seo example snippets



...
'bootstrap' => ['log', 'seo'], // add seo component to application bootstrap
...
'components' => [
	...
    'seo'         => [
        'class' => 'shershennm\seo\Seo',
        'controllerMapping' => [
            'app\controllers' => 'app\seo\controllers', // controller namespace for seo module
        ],

    ],
]



namespace app\seo\controllers;

use Yii;
use shershennm\seo\SeoController;

class SiteController extends SeoController
{
    /**
    * $viewParams array View Params from actionIndex in SiteController
    **/
    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 View::registerMetaTag() function
            ['name' => 'description', 'content' => 'Cool page!'],
        ];
    }

    private function getKeywords()
    {
        // $this->controller instance of current controller
        return implode($this->controller->words, ', ');
    }

	....



namespace frontend\seo\controllers;

use shershennm\seo\OnePageSeoController;

class SiteController extends OnePageSeoController
{
    protected $titles = [
        'site/info' => 'Site Info',
    ];
    protected $wildcardTitles = [
        '/site\/history/' => 'Site History',
    ];
}