Yii Framework Forum: SEO Url - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SEO Url Rate Topic: -----

#1 User is offline   Alfdesign 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-June 09

Posted 09 June 2009 - 12:26 PM

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.

Attached File(s)


0

#2 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 12 July 2009 - 04:01 AM

Have you tested this code?

These two url rules
				'<lang:(sk|en)>/<url>'=>'site/index',
				'<lang:(sk|en)>/<section>'=>'site/section',

might be inappropriate, since there is no way for Yii to know whether the second uri segment is a url or a section.

I think it'd be more acceptable if you define deeper urls like <lang>/section/<section> in order to avoid conflicts.

The same goes to another pair of rules:

				'<lang:(sk|en)>/<section>/<url>'=>'site/section',
				'<lang:(sk|en)>/<section>/<subsection>'=>'site/subsection',

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users