Not Going Inside Controller

i am trying to make MVC without using Gii. i have created view,model and controller manually. and it’s working fine except controller.

form validating from model but it’s not going inside login() of model and controller…

Take a look of my code and please suggest me what’s going wrong with my code…

loginForm.php




<?php


$form=$this->beginWidget(

        'CActiveForm', array(

	'id'=>'login-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

));

?>


<div>

    <?php echo $form->labelEx($model,'Username'); ?>

    <?php echo $form->textfield($model,'username'); ?>

    <?php echo $form->error($model,'username'); ?>

    

</div>


<div>

    <?php echo $form->labelEx($model,'Password'); ?>

    <?php echo $form->passwordfield($model,'password'); ?>

    <?php echo $form->error($model,'password'); ?>

    

</div>


<div class="row button">

    <?php echo CHtml::submitbutton('Login'); ?>

</div>


<?php $this->endWidget(); ?>




Login.php (MODEL)




<?php

class Login extends CFormModel

{

    public $username;

    public $password;

    public $k='kalpit';

    public function login()

    {

        if($this->username==  $this->k)

        {

            var_dump("hi");

            return true;

        }

        else 

        {

            var_dump("sorry");

            return false;

        }

    }

    

    public function rules()

    {

        return array(

            array('username,password','required')

        );

    }

}




LoginController.php




<?php

class LoginController extends Controller

{

    public function actionLoginForm()

    { 

        var_dump("hi");

        $model = new Login();

        

        if($model->login())

        {

            var_dump("hi");

            //$this->redirct('site/index');

        }

        else 

        {

            var_dump("sorry");

        }

        

        $this->render('site/loginForm',array('model'=>$model));

    }

}



Hi I think you can try this


if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

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

			if($model->login()){

				//$this->redirect(CController::createUrl('customer/index'));

				$this->redirect(CController::createUrl('customer/index/tab'));

				return;

			}else{

				Yii::app()->user->setFlash('error',Yii::t("messages",'Invalid email or password'));

				$this->redirect('login');

				Yii::app()->end();


			}

		}

it’s not calling action method only…

Oh sorry just you can write a action





<?php


$form=$this->beginWidget(

        'CActiveForm', array(

        'id'=>'login-form',

         'action'=>'login',//call a action

        'enableClientValidation'=>true,

        'clientOptions'=>array(

                'validateOnSubmit'=>true,

        ),

));

?>

no it’s not working bro…

Hi it’s not calling a controller or just not in model code?

can you post the error?

it’s not showing any error… and it’s not calling controller only… i am printing var_dump() inside actionLoginForm() but it’s not printing anything. so it’s not calling controller only…

and in model it’s calling rules() but not calling login() method… (this is because i am calling login() method from controller so.

Hi,

please see the form action what shuould be generate?

hi,

Please see Model,Controller and view files…

i just want to validate user. now i am just hard coding username and password. later on i will make dynamic.

Hi I see your code is every thing is ok but i think you can check the


var_dump("hi");

die;

i hope it’s works

have you tried my code in your pc? is it working there?

i tried


die;

… still it’s not working

Hi I think you can defind in your index.php file YII_DEBUG is true


defined('YII_DEBUG') or define('YII_DEBUG',true);