谁一开始就是大神?

yii登录之后,显示空白页

views 里面代码

<!DOCTYPE html>
<html>
    <head>
	<title>前台登录</title>
	<link href="<?php echo (Yii::app()->request->baseUrl);?>/assets/index/css/jquery.mobile-1.4.5.min.css" type="text/css" rel="stylesheet">
         <script src="<?php echo Yii::app()->request->baseUrl;?>/assets/index/js/jquery-2.1.4.min.js"></script>
         <script src="<?php echo Yii::app()->request->baseUrl;?>/assets/index/js/jquery.mobile-1.4.5.min.js"></script>
		 <script src="<?php echo Yii::app()->request->baseUrl;?>/assets/index/js/main.js"></script>
	<style>
		.image{
			width:60px;
			height:60px;
		}
		#header{
		}
		.errorMessage {
			color: red;
		}
	</style>
    </head>
    <body>

	<div data-role="page">
	    <div data-role="content">
		<h1>前台登录APP</h1>
		<br><br><br>
		    <?php  $form = $this->beginWidget('CActiveForm'); ?>
		    <?php echo $form->textField($loginForm,'nickname',array('id' =>'user','placeholder'=>'用户名/邮箱')); ?>
		    <?php echo $form->error($loginForm,'nickname');?>

		    <?php echo $form->passwordField($loginForm,'password',array('id' =>'pwd','placeholder'=>'请输入密码'));  ?> 
		    <?php echo $form->error($loginForm,'password');?>

		    <?php echo $form->textField($loginForm,'captcha',array('id' =>'verify','placeholder'=>'请输入验证码'));?>
		    <?php echo $form->error($loginForm,'captcha');?>

		    <?php $this->widget('CCaptcha',array(
    				'showRefreshButton'=>false,
    				'clickableImage' => true,
    				'imageOptions' => array('alt'=>'点击换图',
    			        'title' => '点击换图',
    			        'style' => 'cursor:pointer')
    				     ));?>
    				<br/>
		    <input type="submit" value="登录"> 
		    <?php $this->endWidget(); ?>  
	    </div>
	</div>
	<script>
		
	</script>
    </body>

models里面LoginForm.php文件代码

<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */

class LoginForm extends CFormModel
{
	public $nickname;
	public $password;
	public $rememberMe;
	public $captcha;
	private $_identity;
	
	/**
	 * 声明验证规则。  
	 * 规则,需要用户名和密码,
	 * 和密码需要身份验证。
	 */
	public function rules()
	{
		return array(
			// nickname and password are required
			array('nickname', 'required','message'=>'用户名不能为空'),
			array('password', 'required','message' => '密码不能为空'),
			// rememberMe needs to be a boolean
			array('rememberMe', 'boolean'),
			// password needs to be authenticated
			array('password', 'authenticate'),
			array('captcha','captcha','message'=>'验证码错误'),
		);
	}

	/**
	 * 记住我
	 */
	public function attributeLabels()
	{
		return array(
			'rememberMe'=>'Remember me next time', 
		);
	}

	/**
	 * 判断用户名密码
	 */
	public function authenticate($attribute,$params)
	{
		if(!$this->hasErrors())
		{
			$this->_identity=new UserIdentity($this->nickname,$this->password);
			if(!$this->_identity->authenticate())
				$this->addError('password','用户名或密码错误');
		}
	}

	/**
	*记住登录
	*/
	public function login()
	{
		if($this->_identity===null)
		{
			$this->_identity=new UserIdentity($this->nickname,$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;
		}
		else
			return false;
	}
}

controllers文件里面 LoginController.php 代码

<?php
class LoginController extends Controller
{
	public function actionIndex()
	{
		$loginForm = new LoginForm();
		if(isset($_POST['LoginForm'])){
			$loginForm->attributes=$_POST['LoginForm'];
			if($loginForm->validate()&&$loginForm->login()){
				$this->redirect(array('main/main'));
			}
		}
		$this->render('index',array('loginForm' =>$loginForm));
	}
	public function actions(){
	    return array(
	    	'captcha' => array(
	    		'class' => 'system.web.widgets.captcha.CCaptchaAction',
	    		'height' => 40,
	    		'width' => 80,
	    		'minLength' => 4,
	    		'maxLength' => 4,
	    		//'testLimit' => 999,
	    		),
	    	);
	}
	public function actionOut(){
		Yii::app()->user->logout();
		$this->redirect(array('login/index'));
	}


	public function actionRegister(){
	$registerModel = new Register();
	if(isset($_POST['Register'])){
		//收集信息,保存信息,页面重定向
			$registerModel->attributes=$_POST['Register'];
			if($registerModel->validate()){
				$registerModel->Password=md5($registerModel->Password);
			    if($registerModel->save()){
			    	$this->redirect(array('Check'));
			    }
			}
		}
		//调用添加的视图 
		$this->render('register',array('registerModel' => $registerModel));
	}

}

用户验证的逻辑在protected\components\UserIdentity.php的authenticate()方法下,我估计是你这个方法没改或者写错了。你去检查一下。
你好歹return一下呀。。
贴出maincontroller看看

赞(0) 打赏
未经允许不得转载:菜鸟之家 » yii登录之后,显示空白页

评论 抢沙发

登录

找回密码

注册