CRUD: User name disappers from breadcrumbs and title

Hi there,

I have a basic user editing form, the simplest as it can be, generated in whole by gii. I changed only it’s title and breadcrumbs part to display user name (where originally ID is, if I’m not mistaken). So:


    	$this->pageTitle = 'Edit user';








<h1><?php echo $this->pageTitle ?> &bdquo;<strong><?php echo $model->NAZW; ?></strong>&rdquo;</h1>

If user uses this form and makes user name filed empty (which is incorrect, as this one is required) Yii will handle this properly showing (upon reload) proper error message. But in the same time user name will disappear from both breadcrumbs and page title.

For above code I’ll get then: “Edit user „”” for title and “Main page » Admin » Users » » Edit user” for breadcrumbs.

Where I should get: "Edit user „USERNAME”" for title and "Main page » Admin » Users » USERNAME » Edit user" for breadcrumbs.

Either I’m missing something or form generated by gii takes user name (or any other data) from form model, not actually user model. Strange! Is there any way to fix this?

looks like after you submit the form model is updating attributes to fill the form but doesn’t save it because of error. you might send the username separate from the model.

You answer suggest that this is normal behaviour (?) not an error in my application. And this is what I want to know. If this is normal situation, I’ll try to find a fix for it. Your idea seems interesting. Thank you.

As umutau stated, this is the expected behavior.

You have to take the user name before doing setAttributes and pass it to the view.

public function actionUpdate()



   $username= $user->username;



   $this->render('update', array('model'=>$model, 'username'=>$username));


In the view, for breadcrumbs and page title use $username instead of $model->username.

Thank you for your advices.

But, since this problem occurs only on update and only in case of error (works fine in other views), I will have to update all views (and controllers) to the solution zaccaria provided. Or add some check and either $username or $user->username are empty and print out the one, isn’t.

Thanks again! I just wanted to make myselt sure, if this is normal behaviour or if I made some mistake in the code. EoT.

Thanks again, zaccaria! Works, like a charm! ;}

I would only add, that you did a small typo, if I’m not mistaken. It should be:


$username= $model->username;

not, as you wrote:


$username= $user->username;

Cheers! :]

Of corse, it was a typo… I just wanted to check if you were attentive…


Did I mentioned that I like you very much and find you a very enthusiastic developer? :P :> :]