yiiapp/protected/controllers/SiteController.php Site的控制器模块

<?php

//这里是Site的控制器模块 继承自Controller在是../components/Controller.php文件中
class SiteController extends Controller
{
	/**
	 * Declares class-based actions.
	 * 声明类为基础的行动。
	 */
	public function actions()
	{
		return array(
		    //CAPTCHA行动呈现接触页面上显示的验证码图片
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction', //类名
				'backColor'=>0xFFFFFF,     //背景颜色
			),
			
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			// 页行动“静态”保护存储在'/意见/网站/网页的页面呈现'
            // 它们可以通过访问:index.php的R =网站/网页&视图=文件名?
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 * 这是调用默认的'指数'行动做 
     * 当行动用户没有明确要求。
	 */
	public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// 呈现视图文件
		
		// using the default layout 'protected/views/layouts/main.php'
		// 使用默认的布局 
		$this->render('index');
	}
	
	//测试
	public function actionTest()
	{
	    //echo "<h1>test</h1>";
	    $this->render('test');
	}
	

	/**
	 * This is the action to handle external exceptions.
	 * 这是行动来处理外部例外。
	 */
	public function actionError()
	{
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest) //如果是ajax请求,直接返回,如果是其它的话,返回错误信息
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}

	/**
	 * Displays the contact page
	 * 显示联系人页面...
	 */
	public function actionContact()
	{
		$model=new ContactForm;
		
		//开始提交
		if(isset($_POST['ContactForm']))
		{
			
			$model->attributes=$_POST['ContactForm'];
			//验证
			if($model->validate())
			{
				//名称
				$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
				//标题
				$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
				//头文件
				$headers="From: $name <{$model->email}>\r\n".
					"Reply-To: {$model->email}\r\n".
					"MIME-Version: 1.0\r\n".
					"Content-type: text/plain; charset=UTF-8";

				//开始发送
				mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
				//
				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
				$this->refresh();
			}
		}
		$this->render('contact',array('model'=>$model));
	}

	/**
	 * Displays the login page
	 * 显示登录页面
	 */
	public function actionLogin()
	{
		$model=new LoginForm; //实例化LoginForm类

		// if it is ajax validation request
		//如果是ajax请求登陆
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		// 收集用户输入的数据
		if(isset($_POST['LoginForm']))
		{
			//var_dump($_POST['LoginForm']);
			//die();
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			// 如果有效验证用户输入,并重定向到前一页
			//if($model->validate() && $model->login())
			if($model->login())
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		// 显示登录页面
		$this->render('login',array('model'=>$model));
	}

	/**
	 * Logs out the current user and redirect to homepage.
	 * 注销当前用户重定向到首页。
	 */
	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
}

  

posted @ 2013-06-22 17:32  简单--生活  阅读(360)  评论(0)    收藏  举报
简单--生活(CSDN)