seo SEO - Search engine optimization in no time

  1. Links
  2. What's included?
  3. Usage
  4. Changes

Current version 0.9.2c

SEO is a modest extension which allows for easy search engine optimization within your Yii-application.

Links

What's included?

  • SeoRecordBehavior - Active record behavior for defining the model URL
  • SeoControllerBehavior - Controller behavior for setting page meta data
  • SeoFilter - Controller filter for correcting incorrect URLs
  • SeoMetaWidget - Widget for rendering page meta data

Usage

I assume that you have some basic knowledge about search engine optimization.

SeoRecordBehavior

To define the URL for your model add the SeoRecordBehavior to your model:

public function behaviors()
{
	return array(
		.....
		array(
			'class'=>'ext.seo.components.SeoRecordBehavior',
			'route'=>'model/view',
			'params'=>array('id'=>$this->id, 'name'=>$this->name),
		),
	);
}

In this case we add the following rule to the UrlManager configuration:

'urlManager'=>array(
	'urlFormat'=>'path', // when doing SEO, this should always be set to 'path'
	'rules'=>array(
		.....
		'model/<id:\d+>-<name>.html'=>'model/view', // e.g. model/1-model+name.html
	),
),

Note that you need to include all params in your URL rewrite rule that you specified for the SeoRecordBehavior, in this case id and name.

When rendering a link to 'model/view', instead of using the array format:

array('model/view', 'id'=>$model->id, 'foo'=>'bar')

Use the getUrl or getAbsoluteUrl method:

$model->getUrl(array('foo'=>'bar')

This will ensure that the correct URL is displayed everywhere.

SeoFilter

To automatically do 301 redirects for incorrect URLs add the SeoFilter to your controller:

public function filters()
{
	return array(
		.....
		array('ext.seo.components.SeoFilter + view'), // apply the filter to the view-action
	);
}

This is useful when the model name has been updated an it's used in the SEO optimized URL. In other words this will automatically correct the URL with a proper redirect when e.g. a crawler visits an old URL.

SeoControllerBehavior

To allow for setting page meta data add the SeoControllerBehavior to your controller:

public function behaviors()
{
	return array(
		.....
		'seo'=>array('class'=>'ext.seo.components.SeoControllerBehavior'),
	);
}

You can now set the page meta data and canonical in your view:

$this->metaKeywords = 'these, are, my, sample, page, meta, keywords';
$this->metaDescription = 'This is a sample page description';
$this->addMetaProperty('fb:app_id',Yii::app()->params['fbAppId']);
$this->canonical = $model->getAbsoluteUrl(); // canonical URLs should always be absolute
SeoMeta

To render SEO related tags call the SeoHead widget in your layout:

<?php Yii::app()->controller->widget('ext.seo.widgets.SeoHead',array(
	'httpEquivs'=>array(
		'Content-Type'=>'text/html; charset=utf-8',
		'Content-Language'=>'en-US'
	),
	'defaultDescription'=>'This is a sample page description.',
	'defaultKeywords'=>'these, are, my, default, sample, page, meta, keywords',
)); ?>

In version 0.9.2 SeoMeta was renamed to SeoHead.

SeoTitle

Since 0.9.2 SeoTitle is rendered by SeoHead so you no longer need to call it yourself.

You don't have to set the page title for every single view, instead the widget will build the title from your breadcrumbs.

If you wish you can still set the page title as a string in your view:

<?php $this->pageTitle = 'Model name - Parent name - Application name'; ?>

Or you can set the page title as an array:

<?php $this->pageTitle = array(
	'Model name',
	'Parent name',
	'Application name',
); ?>

Changes

Oct 21, 2011
  • Release 0.9.2c
  • Added a check to prevent recursive canonical redirects
Oct 20, 2011
  • Release 0.9.2b
  • Fixed a typo in the SeoHead widget
Oct 20, 2011
  • Release 0.9.2
  • Renamed the SeoMeta widget to SeoHead
  • SeoHead now renders the SeoTitle as well
Oct 18, 2011
  • Release 0.9.1b
  • Fixed an issue with parsing breadcrumbs for the SeoTitle widget
Oct 14, 2011
  • Release 0.9.1
  • Added the SeoTitle widget
  • Renamed the SeoMetaWidget to SeoMeta
Oct 12, 2011
  • Release 0.9.0
  • Initial release
32 0
79 followers
4 156 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: Chris83
Created on: Oct 12, 2011
Last updated: 6 years ago

Downloads

show all

Related Extensions