Changing home page & user-friendly URLs

Okay, I’m just started work with Yii recently. I have two questions.

I’m working on a website and want my pages to be dynamic so I CRUD’d (correct term???) a table name ‘page’ which basically has an id (pk), title (to be displayed), link title (title I want to be shown in the URL) and the actual content.

At the moment, to view a specific page, I use the following url: index.php?r=page/view&id=x where x is the page id (e.g. 1).

I’ve tried to change it to /page/x where x is the link title (e.g. about) however it doesn’t seem to be working. What exactly to I have to change for it to work in such a manner? I added the getUrl() property and have played around with the URLManager but I’m guessing I have to change something else before it’ll start working. Any ideas?

Second question is related to the home page. Instead of defaulting to index.php I want to change it to a specific page, e.g. page/view&id=1. If I change the defaultController to that, though, in the config file I get an error. I can change it to page fine, and it’ll list all the pages I have, but if I try to make it point to a specific page, it’ll give me an error. Any ideas on how to achieve this?

bump.

Make sure you’ve set the urlFormat property to ‘path’ as described in the documentation:




array(

    ......

    'components'=>array(

        ......

        'urlManager'=>array(

            'urlFormat'=>'path',

        ),

    ),

);



http://www.yiiframework.com/doc/guide/topics.url

try using url rules like this:




array(

    ......

    'components'=>array(

        ......

        'urlManager'=>array(

            'urlFormat'=>'path',

            'rules'=>array(

                'page/<id:\d+>'=>'page/view',

                'page/<title>'=>'page/view',

            ),

        ),

    ),

);



the first rule will translate ‘mydomain.com/index.php/page/1’ to ‘mydomain.com/index.php?r=page/view&id=1’.

The second rule will translate ‘mydomain.com/index.php/page/Yii%20is%20the%20top’ to ‘mydomain.com/index.php?r=page/view&title=Yii%20is%20the%20top’.

This is in de section about the urlManager of the definitive guide.