help needed, new to yii Error - CException

When I try to log in, I get this error; however, if I back out, it did successfully log me in, it just wont redirect me or whatever. Im new to yii and php, so please dont expect I will understand a complicated answer lol… Thank you for your help in advance… Just trying to move along.

CException

LoginForm and its behaviors do not have a method or closure named "login".

/var/www/yii/framework/base/CComponent.php(266)

254 public function __call($name,$parameters)

255 {

256 if($this->_m!==null)

257 {

258 foreach($this->_m as $object)

259 {

260 if($object->getEnabled() && method_exists($object,$name))

261 return call_user_func_array(array($object,$name),$parameters);

262 }

263 }

264 if(class_exists(‘Closure’, false) && $this->canGetProperty($name) && $this->$name instanceof Closure)

265 return call_user_func_array($this->$name, $parameters);

266 throw new CException(Yii::t(‘yii’,’{class} and its behaviors do not have a method or closure named “{name}”.’,

267 array(’{class}’=>get_class($this), ‘{name}’=>$name)));

268 }

269

270 /**

271 * Returns the named behavior object.

272 * The name ‘asa’ stands for ‘as a’.

273 * @param string $behavior the behavior name

274 * @return IBehavior the behavior object, or null if the behavior does not exist

275 */

276 public function asa($behavior)

277 {

278 return isset($this->_m[$behavior]) ? $this->_m[$behavior] : null;

Stack Trace

#0

– /var/www/gRaiders/protected/controllers/SiteController.php(104): CComponent->__call("login", array())

099 if(isset($_POST[‘LoginForm’]))

100

{

102 $form->attributes=$_POST[‘LoginForm’];

103 // validate user input and redirect to previous page if valid

[color="#483D8B"]104 if($form->validate() && $form->login()) $form->redirect(Yii::app()->user->returnUrl);

105 }

106 //display the login form

107 $this->render(‘login’,array(‘form’=>$form));

108 }[/color]

When I try to login, I get this error; however, I can back out and it DOES log me in… it just doesn’t redirect me successfully. Thank you in advance for your help. I appreciate it.

Try to create a new webapp and check if there the login works for you… if it works compare the code from that code with yours to find the problem.

I have a similar problem, after reading Larry Ullmans authentication guide (I’m not allowed to link to urls it says)

I guess it’s this part:

public function login()


{


	if($this->_identity===null)


	{


		$this->_identity=new UserIdentity($this->username,$this->password);


		$this->_identity->authenticate();


	}


	if($this->_identity->errorCode===UserIdentity::ERROR_NONE)


	{


		$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days


		Yii::app()->user->login($this->_identity,$duration);


		return true;


	}

Then it comes with error: Property "LoginForm._identity" is not defined.

I’m a brand new user of Yii framework, but i have a feeling that maybe it’s because larry ullmans guide is outdated? Due some of his methods arent like the standard ones i see…??

Okai, i might have found the problem, but not the solution…

In the guide’s “authenticate” model section he writes the identity like $identity

and in the “standard” it’s written like: $this->_identity

When i try to change $identity to $this->_identity it’s then making errors in the case section:


switch($identity->errorCode)

			{

				case UserIdentity::ERROR_NONE:

					Yii::app()->user->login($identity);

					break;

				case UserIdentity::ERROR_USERNAME_INVALID:

					$this->addError('email','Email address is incorrect.');

					break;

				default: // UserIdentity::ERROR_PASSWORD_INVALID

					$this->addError('password','Password is incorrect.');

					break;

			}

So i’m not sure how i should edit this ?

i did some more troubleshooting, and actually the script works fine… It logs me in and so, but still comes up with error…

When i remove "public function login()" it comes with error: "LoginForm and its behaviors do not have a method or closure named "login"."

I have an idea that it might need an Return to close the function - i have tried with return true, but that doesnt work…

Okai i think i might have worked this out…

I’m a rookie in Yii, so i make stupid errors… :)

It was in the DefaultController of my admin module it was wrong…

It came with the following:


if($model->validate() && $model->login())

$this->redirect(Yii::app()->user->returnUrl);

i changed to:


if($model->validate())

$this->redirect(Yii::app()->request->redirect('index'));

The old redirect sent me to my localhost start if i went directly to the admin module, så had to change it to make sure i ended in my index, which of course has accessrules!