Mvc Yii Process

Hi am new in yii and I have read the tutorials but I cannot get the flow how yii mvc relate. e.g I have a login form. where the user inputs their username and password.(saved in …views/users/login.php).I have a controller logincontroller.php(saved in …controllers/logincontroller.php) in it the public function actionlogin. and the model loginform in the models folder.

Could someone please assist me in getting to know how this relate. i.e what happens when the user clicks the login button in the view.

You can investigate code of the example shipped with Yii.

Basically, user clicks submit, then the form data is sent via POST to its action url (to current url in case of empty action value).

This request is being processed by controller’s action (actionLogin in your case), that fills and validates the form model (LoginForm in your case) and then does something depending on validation result (logs user in and redirects or renders the form once again displaying validation errors).

thanks orey

But I get this error when I click login button.

include(user.php): failed to open stream: No such file or directory

C:\wamp\www\yii\framework\YiiBase.php(427)

415 {

416 include($classFile);

417 if(YII_DEBUG && basename(realpath($classFile))!==$className.’.php’)

418 throw new CException(Yii::t(‘yii’,‘Class name “{class}” does not match class file “{file}”.’, array(

419 ‘{class}’=>$className,

420 ‘{file}’=>$classFile,

421 )));

422 break;

423 }

424 }

425 }

426 else

427 include($className.’.php’);

428 }

429 else // class name with namespace in PHP 5.3

430 {

431 $namespace=str_replace(’\\’,’.’,ltrim($className,’\\’));

432 if(($path=self::getPathOfAlias($namespace))!==false)

433 include($path.’.php’);

434 else

435 return false;

436 }

437 return class_exists($className,false) || interface_exists($className,false);

438 }

439 return true;

Stack Trace

#0

C:\wamp\www\yii\framework\YiiBase.php(427): YiiBase::autoload()

#1

unknown(0): YiiBase::autoload("user")

#2

C:\wamp\www\hospital\protected\components\UserIdentity.php(41): spl_autoload_call("user")

36 class UserIdentity extends CUserIdentity

37 {

38 private $_id;

39 public function authenticate()

40 {

41 $record=user::model()->findByAttributes(array(‘username’=>$this->username));

42 if($record===null)

43 $this->errorCode=self::ERROR_USERNAME_INVALID;

44 else if($record->password!==crypt($this->password,$record->password))

45 $this->errorCode=self::ERROR_PASSWORD_INVALID;

46 else

#3

C:\wamp\www\hospital\protected\models\LoginForm.php(52): UserIdentity->authenticate()

47 public function authenticate($attribute,$params)

48 {

49 if(!$this->hasErrors())

50 {

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

52 if(!$this->_identity->authenticate())

53 $this->addError(‘password’,‘Incorrect username or password.’);

54 }

55 }

56

57 /**

#4

C:\wamp\www\yii\framework\validators\CInlineValidator.php(42): LoginForm->authenticate("password", array())

#5

C:\wamp\www\yii\framework\validators\CValidator.php(213): CInlineValidator->validateAttribute(LoginForm, "password")

#6

C:\wamp\www\yii\framework\base\CModel.php(159): CValidator->validate(LoginForm, null)

#7

C:\wamp\www\hospital\protected\controllers\SiteController.php(94): CModel->validate()

89 // collect user input data

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

91 {

92 $model->attributes=$_POST[‘LoginForm’];

93 // validate user input and redirect to the previous page if valid

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

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

96 }

97 // display the login form

98 $this->render(‘login’,array(‘model’=>$model));

99 }

#8

C:\wamp\www\yii\framework\web\actions\CInlineAction.php(49): SiteController->actionLogin()

#9

C:\wamp\www\yii\framework\web\CController.php(308): CInlineAction->runWithParams(array())

#10

C:\wamp\www\yii\framework\web\CController.php(286): CController->runAction(CInlineAction)

#11

C:\wamp\www\yii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array())

#12

C:\wamp\www\yii\framework\web\CWebApplication.php(282): CController->run("login")

#13

C:\wamp\www\yii\framework\web\CWebApplication.php(141): CWebApplication->runController("site/login")

#14

C:\wamp\www\yii\framework\base\CApplication.php(180): CWebApplication->processRequest()

#15

C:\wamp\www\hospital\index.php(13): CApplication->run()

2013-11-07 01:08:46 Apache/2.4.4 (Win32) PHP/5.4.16 Yii Framework/1.1.14

Your model file should be named User.php, not user.php

thanks alot…am starting to enjoy my yii framework.