Yii Framework Forum: Mvc Yii Process - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Mvc Yii Process Rate Topic: -----

#1 User is offline   kamau 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 04-November 13
  • Location:Nairobi

Posted 06 November 2013 - 08:36 AM

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.
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 06 November 2013 - 08:47 AM

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).
God is real unless declared as integer
0

#3 User is offline   kamau 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 04-November 13
  • Location:Nairobi

Posted 06 November 2013 - 09:11 AM

View PostORey, on 06 November 2013 - 08:47 AM, said:

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
0

#4 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 06 November 2013 - 09:14 AM

Your model file should be named User.php, not user.php
God is real unless declared as integer
1

#5 User is offline   kamau 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 04-November 13
  • Location:Nairobi

Posted 07 November 2013 - 03:33 AM

View PostORey, on 06 November 2013 - 09:14 AM, said:

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




thanks alot...am starting to enjoy my yii framework.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users