Refactored the basic app.

This commit is contained in:
Qiang Xue 2013-08-10 07:33:24 -04:00
parent 0d86b89cbe
commit 5072e526be
8 changed files with 132 additions and 87 deletions

View File

@ -7,7 +7,7 @@ return array(
'modules' => array(
'debug' => array(
'class' => 'yii\debug\Module',
'enabled' => YII_DEBUG && YII_ENV_DEV,
'enabled' => YII_ENV_DEV,
),
),
'components' => array(
@ -15,9 +15,11 @@ return array(
'class' => 'yii\caching\FileCache',
),
'user' => array(
'class' => 'yii\web\User',
'identityClass' => 'app\models\User',
),
'errorHandler' => array(
'errorAction' => 'site/error',
),
'log' => array(
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(

View File

@ -12,9 +12,12 @@ class SiteController extends Controller
public function actions()
{
return array(
'error' => array(
'class' => 'yii\web\ErrorAction',
),
'captcha' => array(
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_DEV ? 'testme' : null,
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
),
);
}

View File

@ -7,6 +7,7 @@ use yii\helpers\Html;
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?php echo Html::encode($this->title); ?></h1>
<p>
@ -14,4 +15,4 @@ $this->params['breadcrumbs'][] = $this->title;
</p>
<code><?php echo __FILE__; ?></code>
</div>

View File

@ -11,13 +11,16 @@ use yii\captcha\Captcha;
$this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?php echo Html::encode($this->title); ?></h1>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php return; endif; ?>
<?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
@ -40,3 +43,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php ActiveForm::end(); ?>
</div>
</div>
<?php endif; ?>
</div>

29
views/site/error.php Normal file
View File

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var string $name
* @var string $message
* @var Exception $exception
*/
$this->title = $name;
?>
<div class="site-error">
<h1><?php echo Html::encode($this->title); ?></h1>
<div class="alert alert-danger">
<?php echo nl2br(Html::encode($message)); ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>

View File

@ -2,8 +2,10 @@
/**
* @var yii\base\View $this
*/
$this->title = 'Welcome';
$this->title = 'My Yii Application';
?>
<div class="site-index">
<div class="jumbotron">
<h1>Congratulations!</h1>
@ -48,4 +50,4 @@ $this->title = 'Welcome';
</div>
</div>
</div>

View File

@ -10,6 +10,7 @@ use yii\widgets\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?php echo Html::encode($this->title); ?></h1>
<p>Please fill out the following fields to login:</p>
@ -26,3 +27,4 @@ $this->params['breadcrumbs'][] = $this->title;
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
<?php
// comment out the following line to disable debug mode
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');