Current version 0.9.2c
SEO is a modest extension which allows for easy search engine optimization within your Yii-application.
I assume that you have some basic knowledge about search engine optimization.
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.
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.
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
To render SEO related tags call the SeoHead widget in your layout:
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.
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:
$this->pageTitle = 'Model name - Parent name - Application name';
Or you can set the page title as an array:
$this->pageTitle = array( 'Model name', 'Parent name', 'Application name', );
Total 20 comments
Hy, i use the MetaHead widget with the metaproperty og:image. But i wanna overwrite in another controller this property, dont overwrite this.
Example controller:
include(Controller.php) [function.include]: failed to open stream: No such file or directory
Thanks for this great extension...
But I want to implement this into the index page too.
For example , I have model "questions" belongs to "category"..(cid=>category_id)
So my url is something like
How can I convert it into:
Thanks so much for the help!
Great work as always..! Thanks.
Thanks again!
Sorry for the inconvenience. Seems like a merge gone bad.
You can report issues here: https://bitbucket.org/Crisu83/yii-seo/issues/new
Thansk to you for such an amazing extension!!! I just love it
You need to update your files again, I think your upload missed the canonical part described in the documentation
that throws an error, I had to add the attribute to the Controller Behavior and modify the SeoHead acordinly.
pd: should i be posting issues/bug somewhere else? Im feeling like this is not the right place :P
Thanks for reporting this issue. It has been fixed in the newest release (0.9.2b).
There is a bug in the new SeoHead widget on line 109:
should be:
I actually had it like that in the beginning, but you're right that it would probably be better to use a single method.
The reason why I choose to have to separate methods was because Yii has two different methods. Could you explain in detail why you'd prefer a single method for this?
I have modified the SeoRecordBehavior a little, to allow the generation of Absolute URLs, i needed this when generating my sitemap, and could be usefull for other cases:
Now I understand what you're getting at. Updating of the content is done when e.g. the Googlebot crawls your site, if content has changed it will notice it. However, if you use the name in the URL and you change the name, then the old URL will be incorrect and we need to tell the crawlers that the page has been moved. This can be done with the SeoFilter.
Does this answer your question?
Google says frequent updation of files will be an advantage in case of SEO. Updation files means, actually what kind of updation, if we changed the file name its an updation right ? if we changing the content it would be an updation right ? if we cahnge the content of a home page (i mean index page ) by executing one crone file in my server, i mean i will we done on every day morning at a constant time, which will open the index.php file, and edit the index.php by removing somelines, and then adding some lines (some times it may the same). have you got the point ? does it works fine in case of SEO ? this is my question ...!!
I'm sorry but I'm not really sure what you mean, could you try rephrase your question?
Is this SEO Extension will do the all the SEO things, I means its enough right? does it need any thing else for SEO purpose ? how to make the regular updation of the files made easy ? is it right to put one crone file and and update the file ?
No it doesn't but it could, I'll add this for the next release. I'm also thinking that maybe a single widget would be enough for outputting the SEO tags in the layout.
This was caused by a bug in the widget. I've fixed the issue in the newest version (0.9.1b). Sorry for the inconvenience.
Im getting Array to string conversion when using arrays for breadcrumbs like:
Chaging line 43 in SeoTitle.php to:
Fixes the problem
Does this extension handle conical meta?
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
I tried to explain it in the "Usage" section. Could you please be more specific on what you don't understand I'll try to answer your questions.
Thanks in advance.
Leave a comment
Please login to leave your comment.