0

i have implemented project in Yii. i have issue with URL manager configuration. I done URL management successfully but when i rendering the one i want to be display only name ie

'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
                            'Home'=>'site/index',
            //'cuisine'=>'recipe/index3',

            'cuisine/<:\w+>/<id:\d+>/' => 'recipe/index3',
                            //'<id:\w+>/'=>'recipe/index3',
                            '<title:.*?>/p/<id:\d+>'=>'product/view',
            'holidays/<name:\w+>/<id:\d+>/'=>'recipe/index1',
            'calories/<name:\w+>/<id:\d+>/'=>'recipe/index2',

above code is working fine. but recipe/index3 instead of cuisine. i want to be show. i given above statement then i commented because its not working so that. the next statement is working fine. but when render the page like wise displaying

http://kitchenking.ebhasin.com/recipe/index3/name/German

in above link. wants to be show like this.

http://kitchenking.ebhasin.com/cuisine/German

2 Answers 2

1

Have you tried this:

'cuisine/<name:\w+>/<id:\d+>/' => 'recipe/index3',
2
1

Remove the ID from your rule:

'cuisine/<name:\w+>' => 'recipe/index3',

The proper way to allow titles with multiple spaces, is to have another field called "slug", where you copy the title and convert all whitespaces into dashes before you save. Use the slug for URLs instead of title. There is no simpler solution for this.

Put this in your model:

protected function beforeSave() {
    $this->slug = preg_replace('/[^a-z A-Z]+/', '-', $this->title);
    return parent::beforeSave();
}

Then use this for URLs:

<a href="/cuisine/<?= $model->slug ?>"><?= $model->title ?></a>
2
  • this comment is working earlier but. if table data two words ie(holiday recipes) if one word without white space ie(holiday). above code is working. please tell how to over come these issue
    – Jay kumar
    Mar 12, 2014 at 7:21
  • pl suggest me one sample coding
    – Jay kumar
    Mar 12, 2014 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.