Login Widget and design fault, some suggestions?

Hi, i'm new at Yii but not to php, decided a week ago to use this framework and i am really liking it (even if i've not gone too far because i code in my spare time)

Like stated in the topic is clearly a design fault of my application.

I have created a login widget similar to the one the blog tutorial BUT i don't use the LoginFormclass of the base webapp, i preferred the yii-skeleton-app approach of having the login action in the User model.

This widget is shown in all the pages so the users can login whenever they want, the problem is that in the register page, the input errors are shown in the login widget too.

The second, worst problem is that, having a rule that says that logged users can't register, if a try to login from the register after the refresh it says that i am not authorized.

I tried many solutions, but i think the easiest (and best) one would be to simply not show the login widget in the user/register and user/login pages, how can i achieve this?

Sorry for writing that much :)

  1. Are you using the same model object for both login form and register form? They should be different.

  2. In your view, you may use

<?php if(Yii::app()->user->isGuest): ?>

<?php $this->widget('LoginWidget'); ?>

<?php endif; ?>

Tnx for the reply qiang

I have this in my portlet, and when the user is guest it shows the login form or user information if he is logged.

	public function renderContent()


		if (Yii::app()->user->isGuest) {		

			$user=new User;


			echo $_POST['action'];















But if you are registering you are a guest so it shows and you can login form the register page (causing the rule to deny you to reload the page), so what i want is to show the portlet based also on the page you are.

I could check the r get parameter i think, but maybe there is a better method.

Could you be so gentle to explain me why i should use different models for registering and login?

I have actionRegister and actionLogin with different scenarios for the rules inside the User model, i saw it done like this in Jonah's yii-skeleton-app and liked it.

I mean using different model objects, not classes.

So your problem is: on the register page, validation errors are displayed on both the register form and the login form? Are they using the same model [object]?

it shows even using different objects because the validation is done after checking


and being User the name of the class both forms put the data there.

(or am i mistaken?)

By the way, my real concern wasn't the validation errors showing, because i decided that i didn't want at all to show both forms together.

So what i have done is this, on the main view:

<?php if(($_GET[r]!=="user/register")&&($_GET[r]!=="user/login")) $this->widget('LoginPortlet'); ?>

So it shows everywhere except on the two pages that already have a form.

There is a more elegant solution tha checking the r parameter maybe?

Tnx for the patience

Since you have two user-related forms in one page, you should use isset($_POST['buttonName']) to check the form submission. Using isset($_POST['User']) would respond to both of the form submissions, which is not expected.

Ok perfect, thank you.

That, in fact, was my solution prior to making the widget not display at all on the register and login pages.