Skip to content

Instantly share code, notes, and snippets.

@petrabarus
Created September 1, 2012 15:56
Show Gist options
  • Save petrabarus/3578305 to your computer and use it in GitHub Desktop.
Save petrabarus/3578305 to your computer and use it in GitHub Desktop.
/**
* In the config
*/
return [
'components' => [
'urlManager' => [
'rules' => [
//....
//let's assume 'view' is not eligible for a username :)
'member/<username:\w+>' => 'member/view',
//....
]
]
]
];
/**
* In the controller
*/
class MemberController extends \CController {
public function actionView($username){
$user = User::model()->find([
'condition' => 'username = :username',
'params' => [
':username' => $username
]
]);
if ($user === NULL){
throw new CHttpException(404);
}
$this->render('view', [
'user' => $user
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment