Dynamic generation of page meta information (from DB,...)

[font="Lucida Sans Unicode"]Hi guys,

I have had a browse through the forum about this topic, but didn’t come across anything specifically dealing with my question.

I am fairly new to Yii, however would like to solve my problem in a generic and elegant way if possible, without implementing any dirty hacks if that makes sense :wink:

I am sure I am not the first person trying to work out a solution for this topic.

I am planning to use several content views (both static and dynamic ones) as part of my project, whilst using a generic layout-view.

Now, for purposes of SEO,etc. I would like to have proper and expressive meta-tags set in the head area of my HTML document, depending on the respective content view chosen by my controller.

I have currently drafted a solution which looks like this:

  1. Set up a table in DB where I am storing(/configuring) relevant information (incl. meta information and page title,…) per content page.

  2. I derived and extended controler class from CController by properties for pageAuthor, pageRobots, pageKeywords,… (whichever meta information I need), which I am deriving my actually used controller from.

  3. Before rendering my page (beforeRender) I am trying to fetch matching record from my backend-DB (identified via controller_id, action_id and view_name) and populate my attributes with it.

  4. Via registerMetaTag() I am setting my meta tags based on information fetched from DB

  5. Tags are nicely generated during rendering and principally all works fine

Now whilst my approach is generally working and as it is such a basic requirement for almost every website as I think, I was wondering whether anyone is aware about some more generic/elegant approach or some existing extension which can be used to accomplish this task?

Any advice would be appreciated.[/font]

I think your solution is OK and you can search forum and extensions for "SEO" term to find some other solutions.

Like these:

http://www.yiiframework.com/extension/seo - I did not used it, but looks similar to your approach

http://www.yiiframework.com/extension/yii-seo-behavior - one more

http://www.yiiframework.com/extension/cms - here meta data is stored along with content models, each model which can be displayed as a site page has meta_descrioption, meta_keywords, etc fields, so the user can edit content and meta data in the admin interface.

Thanks very much for those recommendations seb.

I will definitely have a thorough browse through the existing extensions in future.

Having a look at those options I have decided to go with the "seo" extension as it provides nice integration and sufficient features for my purpose, yet being extremely light-weight.

[color="#006400"]/* moved from tips forum to Yii 1.1 general discussion */[/color]