3
class SiteController extends Controller
6
* Declares class-based actions.
8
public function actions()
11
// captcha action renders the CAPTCHA image displayed on the contact page
13
'class'=>'CCaptchaAction',
14
'backColor'=>0xFFFFFF,
16
// page action renders "static" pages stored under 'protected/views/site/pages'
17
// They can be accessed via: index.php?r=site/page&view=FileName
19
'class'=>'CViewAction',
25
* This is the default 'index' action that is invoked
26
* when an action is not explicitly requested by users.
28
public function actionIndex()
30
// renders the view file 'protected/views/site/index.php'
31
// using the default layout 'protected/views/layouts/main.php'
32
$this->render('index');
36
* This is the action to handle external exceptions.
38
public function actionError()
40
if($error=Yii::app()->errorHandler->error)
42
if(Yii::app()->request->isAjaxRequest)
43
echo $error['message'];
45
$this->render('error', $error);
50
* Displays the contact page
52
public function actionContact()
54
$model=new ContactForm;
55
if(isset($_POST['ContactForm']))
57
$model->attributes=$_POST['ContactForm'];
58
if($model->validate())
60
$headers="From: {$model->email}\r\nReply-To: {$model->email}";
61
mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
62
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
66
$this->render('contact',array('model'=>$model));
70
* Displays the login page
72
public function actionLogin()
76
// if it is ajax validation request
77
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
79
echo CActiveForm::validate($model);
83
// collect user input data
84
if(isset($_POST['LoginForm']))
86
$model->attributes=$_POST['LoginForm'];
87
// validate user input and redirect to the previous page if valid
88
if($model->validate() && $model->login())
89
$this->redirect(Yii::app()->user->returnUrl);
91
// display the login form
92
$this->render('login',array('model'=>$model));
96
* Logs out the current user and redirect to homepage.
98
public function actionLogout()
100
Yii::app()->user->logout();
101
$this->redirect(Yii::app()->homeUrl);
b'\\ No newline at end of file'