I have a UserController in which i have the below actionView and LoadModel methods.
I have a user table which has username as the primarykey.
The actionView method is working fine only if the username is a number. If the username is a string like ‘abc’
the i am getting the message The system is unable to find the requested action "abc".
However i am able to access the model using the below URL
localhost/app/index.php/user/view/id/abc
but not with
localhost/app/index.php/user/abc
Can anyone help me with this
public function actionView($id)
{
Yii::trace('youoop','trace');
$this->render('view',array('model'=>$this->loadModel($id),));
}
public function loadModel($id)
{
$model=User::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
"<id:\d+>" says that "id" should be numerical. So when you provide a non-numerical "id", it will not be treated correctly by this set of rules.
But you will not be able to solve the problem by simply changing “<id:\d+>” to “<id:\w+>”. If you would do so, then all the urls with the pattern of “<\w+>/<\w+>” will be routed to “<controller>/view”. … I don’t have a quick solution right now.
Anyway, you would want to check the guide. URL Management
en el config/main.php cambia algunos parametros, algunos d+ por w+ y unos w+ por unos d+. y que quede de esta manera a mi me funciono. debe quedar asi.
where even if you have any characters in the id you will be redirected to view of mycontroller
Note: As Softark said if you directly change \d+ to \w+ , it would redirect in case of any controllers which is true and not a good idea. But here we are allowing this in case of only one controller named mycontroller.