Page 1 of 1

Url's friendly

PostPosted: 05 Dec 2012, 12:13
by Drubilar
Hi, you know any way to transform URL like "property/45" to "{property type} / {page title}"?
Regards

Re: Url's friendly

PostPosted: 05 Dec 2012, 14:23
by Xpycm
сonfig/main.php file
in the section 'rules' comment the line:
Code: Select all
property/<id:\d+>'=>'apartments/main/view',


protected/modules/apartments/models/Apartment.php file
instead of:
Code: Select all
public function getUrl() {
    //$tmp = 'title_'.Yii::app()->language;
    return Yii::app()->createUrl('/apartments/main/view', array(
        'id' => $this->id,
        //'title' => $this->$tmp,
    ));
}
 


write:
Code: Select all
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,
    ));
}
 


protected/components/CustomUrlManager.php file
to add the method init() before parseMyInitRules() method:
Code: Select all
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();
}
 


and instead of:
Code: Select all
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;
}
 


it is needed:
Code: Select all
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;
}
 


protected/modules/viewallonmap/components/ViewallonmapWidget.php file
after:
Code: Select all
$criteria = new CDbCriteria; 


write:
Code: Select all
$criteria->with = array('objType'); 


I have described to you everything that our forum allows.

At forum we do not help for more global changes in the code.
You can send us the list of changes that you need via a contact form http://monoray.net/contact.
We evaluate it and say you the price.

Re: Url's friendly

PostPosted: 11 Dec 2012, 14:39
by Drubilar
work!, thank you very much *BRAVO*
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

Re: Url's friendly

PostPosted: 12 Dec 2012, 07:34
by Xpycm
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


Welcome :-)

From the page "Mapa de Propiedades" link is "/Terreno/Terreno-para-constructora-41.htm". Screenshot - https://www.dropbox.com/s/pqcsexvpzixy5 ... 082723.png

Re: Url's friendly

PostPosted: 12 Dec 2012, 09:07
by Xpycm
Please try clear site cache - viewtopic.php?f=17&t=297