Url's friendly
Posted: 05 Dec 2012, 12:13
Hi, you know any way to transform URL like "property/45" to "{property type} / {page title}"?
Regards
Regards
Discussion of company’s products and Yii framework
https://monoray.net/forum/
property/<id:\d+>'=>'apartments/main/view',
public function getUrl() {
//$tmp = 'title_'.Yii::app()->language;
return Yii::app()->createUrl('/apartments/main/view', array(
'id' => $this->id,
//'title' => $this->$tmp,
));
}
public function getUrl() {
$tmp = 'title_'.Yii::app()->language;
return Yii::app()->createUrl('/apartments/main/view', array(
'id' => $this->id,
'title' => $this->$tmp,
'propertyType' => $this->objType->name_en,
));
}
public function init(){
$this->_myRules = array(
array(
'replace' => array(
'<title:.*?>',
'<id:\d+>',
'<propertyType:.*?>',
),
'route' => 'apartments/main/view',
'pattern' => param('module_apartments_apartmentSeoPattern', '::text/::title-::id.htm'),
'model' => 'Apartment',
'path' => 'application.modules.apartments.models.Apartment',
'seo_text' => 'apartments',
),
);
$this->parseMyInitRules();
parent::init();
}
public function parseMyRules($params, $ampersand)
{
if (!$this->_myRules) {
return;
}
if (isset($params['id']) && isset($params['title'])) {
foreach ($this->_myRules as $rule) {
if (Yii::app()->controller->route == $rule['route']) {
if ($this->_replaceSymb) {
$params['title'] = str_replace($this->_replaceSymb, '-', $params['title']);
}
}
}
}
return false;
}
public function parseMyRules($params, $ampersand)
{
if (!$this->_myRules) {
return;
}
if (isset($params['id']) && isset($params['title'])) {
foreach ($this->_myRules as $rule) {
if (Yii::app()->controller->route == $rule['route']) {
if ($this->_replaceSymb) {
$params['title'] = str_replace($this->_replaceSymb, '-', $params['title']);
}
$title = CHtml::encode($params['title']);
$id = $params['id'];
$seoPattern = $this->parseMyLink(array(
$title,
$id,
$rule['seo_text'],
), $rule['pattern']);
if($seoPattern){
return parent::createUrl('/'.$seoPattern, array(), $ampersand);
}
}
}
}
return false;
}
$criteria = new CDbCriteria;
$criteria->with = array('objType');
Drubilar wrote:
The only observation I make is the URL from the map, here the URL takes the name of the category "apartment" instead of the corresponding.
Example:
from the list:
/Terreno/Terreno-para-constructora-41.htm
from the map link:
/apartments/Terreno-para-constructora-41.htm