Question

Now in my Yii application I have th following userpage access url.

mysite/users/view?username=123

which loads view file of users controller.

What I want to do is to simplify URL to this

mysite/users/123

And entering this I want to access the same page.

Is that possible ? For now my View action of UsersController is here :

public function actionView($username){
    $model = User::model()->findByAttributes(array(
        "username" => $username
    ));
    if($model){
        $this->render("view", array(
            "model" => $model
        ));
    }
}
Was it helpful?

Solution

In the urlManager component within the config/main.php

'user/<username:\d+>' => 'user/view' // will need to change \d+ if not working with numbers only.

That will change the url structure. What did you mean about entering?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top