Hi,
I make SEO URL in MySQL table in following way.
Prepare the MySQL Table
CREATE TABLE `url` ( `id` int(11) NOT NULL auto_increment, `pid` varchar(100) NOT NULL, `lang` varchar(2) NOT NULL, `url` varchar(255)NOT NULL, `model` varchar(100) default NULL, `action` varchar(100) default NULL, `section` varchar(100) NOT NULL, `title` varchar(255) default NULL, `meta_description` varchar(255) default NULL, `meta_keywords` varchar(255) default NULL, `content` text , PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_slovak_ci;
Description
id
= 1
pid
= contact
lang
= en
url
= contact
model
=
action
=
section
=
title
= Contact informations // Page title
meta_description
= // META Description
meta_keywords
= // META Keywords
content
= // text of page
/protected/config/main.php
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, 'rules'=>array( '<lang:(sk|en)>'=>'site/index', '<lang:(sk|en)>/<url>'=>'site/index', '<lang:(sk|en)>/<section>'=>'site/section', '<lang:(sk|en)>/<section>/<url>'=>'site/section', '<lang:(sk|en)>/<section>/<subsection>'=>'site/subsection', '<lang:(sk|en)>/<section>/<subsection>/<url>'=>'site/subsection', ), ),
SiteController.php
<?php /** * SiteController is the default controller to handle user requests. */ class SiteController extends CController { public $metaDescription = null; public $metaKeywords = null; /** * Index action is the default action in a controller. */ public function actionIndex() { $pid = get('url'); $lang = get('lang'); $lang = Yii::app()->language; if ($pid) { $page=Url::model()->find('lang=? AND url=?',array($lang, $pid)); if ($page===null) throw new CHttpException(404, 'Oops. Not found.'); $this->pageTitle = $page->title; $this->metaDescription = $page->meta_description; $this->metaKeywords = $page->meta_keywords; $this->render('show',array( 'page'=>$page, )); } else { // } } public function actionSection() { $pid = get('url'); $lang = get('lang'); $section = get('section'); if ($pid) { $page=Url::model()->find('lang=? AND section=? AND url=?',array($lang, $section, $pid)); if ($page===null) throw new CHttpException(404, 'Oops. Not found.'); } } }
This function will get link from database with description.
l('contact');
function l($pid) { $url = explode("/", $pid); $lang = Yii::app()->language; switch (count($url)) { case 1 : $page = Url::model()->find('lang=? AND pid=?',array($lang, $url[0])); $link = Yii::app()->request->hostInfo."/{$page['lang']}/{$page['url']}"; break; case 2 : $page = Url::model()->find('lang=? AND section=? AND pid=?',array($lang, $url[0], $url[1])); $link = Yii::app()->request->hostInfo."/{$page['lang']}/{$page['section']}/{$page['url']}"; break; case 3 : } $link = "<a href='{$link}'>{$page['title']}</a>"; return $link; }
This process is in progress, but I like to know Your opinion.