Commit bc21de98 by Qiang Xue

Refactored the basic app.

parent 8ee92fdb
...@@ -7,7 +7,7 @@ return array( ...@@ -7,7 +7,7 @@ return array(
'modules' => array( 'modules' => array(
'debug' => array( 'debug' => array(
'class' => 'yii\debug\Module', 'class' => 'yii\debug\Module',
'enabled' => YII_DEBUG && YII_ENV_DEV, 'enabled' => YII_ENV_DEV,
), ),
), ),
'components' => array( 'components' => array(
...@@ -15,9 +15,11 @@ return array( ...@@ -15,9 +15,11 @@ return array(
'class' => 'yii\caching\FileCache', 'class' => 'yii\caching\FileCache',
), ),
'user' => array( 'user' => array(
'class' => 'yii\web\User',
'identityClass' => 'app\models\User', 'identityClass' => 'app\models\User',
), ),
'errorHandler' => array(
'errorAction' => 'site/error',
),
'log' => array( 'log' => array(
'traceLevel' => YII_DEBUG ? 3 : 0, 'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array( 'targets' => array(
......
...@@ -12,9 +12,12 @@ class SiteController extends Controller ...@@ -12,9 +12,12 @@ class SiteController extends Controller
public function actions() public function actions()
{ {
return array( return array(
'error' => array(
'class' => 'yii\web\ErrorAction',
),
'captcha' => array( 'captcha' => array(
'class' => 'yii\captcha\CaptchaAction', 'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_DEV ? 'testme' : null, 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
), ),
); );
} }
......
...@@ -7,11 +7,12 @@ use yii\helpers\Html; ...@@ -7,11 +7,12 @@ use yii\helpers\Html;
$this->title = 'About'; $this->title = 'About';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-about">
<h1><?php echo Html::encode($this->title); ?></h1>
<p> <p>
This is the About page. You may modify the following file to customize its content: This is the About page. You may modify the following file to customize its content:
</p> </p>
<code><?php echo __FILE__; ?></code>
<code><?php echo __FILE__; ?></code>
</div>
...@@ -11,19 +11,22 @@ use yii\captcha\Captcha; ...@@ -11,19 +11,22 @@ use yii\captcha\Captcha;
$this->title = 'Contact'; $this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-contact">
<h1><?php echo Html::encode($this->title); ?></h1>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?> <?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible. Thank you for contacting us. We will respond to you as soon as possible.
</div> </div>
<?php return; endif; ?>
<p> <?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p> </p>
<div class="row"> <div class="row">
<div class="col-lg-5"> <div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'contact-form')); ?> <?php $form = ActiveForm::begin(array('id' => 'contact-form')); ?>
<?php echo $form->field($model, 'name')->textInput(); ?> <?php echo $form->field($model, 'name')->textInput(); ?>
...@@ -39,4 +42,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -39,4 +42,7 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
</div>
<?php endif; ?>
</div> </div>
<?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>
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
/** /**
* @var yii\base\View $this * @var yii\base\View $this
*/ */
$this->title = 'Welcome'; $this->title = 'My Yii Application';
?> ?>
<div class="jumbotron"> <div class="site-index">
<div class="jumbotron">
<h1>Congratulations!</h1> <h1>Congratulations!</h1>
<p class="lead">You have successfully created your Yii-powered application.</p> <p class="lead">You have successfully created your Yii-powered application.</p>
<p><a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p> <p><a class="btn btn-large btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
</div> </div>
<div class="body-content"> <div class="body-content">
<div class="row"> <div class="row">
<div class="col-lg-4"> <div class="col-lg-4">
...@@ -47,5 +49,5 @@ $this->title = 'Welcome'; ...@@ -47,5 +49,5 @@ $this->title = 'Welcome';
</div> </div>
</div> </div>
</div>
</div> </div>
...@@ -10,11 +10,12 @@ use yii\widgets\ActiveForm; ...@@ -10,11 +10,12 @@ use yii\widgets\ActiveForm;
$this->title = 'Login'; $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<h1><?php echo Html::encode($this->title); ?></h1> <div class="site-login">
<h1><?php echo Html::encode($this->title); ?></h1>
<p>Please fill out the following fields to login:</p> <p>Please fill out the following fields to login:</p>
<div class="row"> <div class="row">
<div class="col-lg-3"> <div class="col-lg-3">
<?php $form = ActiveForm::begin(array('id' => 'login-form')); ?> <?php $form = ActiveForm::begin(array('id' => 'login-form')); ?>
<?php echo $form->field($model, 'username')->textInput(); ?> <?php echo $form->field($model, 'username')->textInput(); ?>
...@@ -25,4 +26,5 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -25,4 +26,5 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
</div>
</div> </div>
<?php <?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_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev'); defined('YII_ENV') or define('YII_ENV', 'dev');
......
...@@ -567,7 +567,7 @@ class YiiBase ...@@ -567,7 +567,7 @@ class YiiBase
*/ */
public static function powered() public static function powered()
{ {
return 'Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>.'; return 'Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>';
} }
/** /**
......
...@@ -3,14 +3,32 @@ ...@@ -3,14 +3,32 @@
* @var \Exception $exception * @var \Exception $exception
* @var \yii\base\ErrorHandler $handler * @var \yii\base\ErrorHandler $handler
*/ */
$title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); if ($exception instanceof \yii\web\HttpException) {
$code = $exception->statusCode;
} else {
$code = $exception->getCode();
}
if ($exception instanceof \yii\base\Exception) {
$name = $exception->getName();
} else {
$name = 'Error';
}
if ($code) {
$name .= " (#$code)";
}
if ($exception instanceof \yii\base\UserException) {
$message = $exception->getMessage();
} else {
$message = 'An internal server error occurred.';
}
?> ?>
<?php if (method_exists($this, 'beginPage')) $this->beginPage(); ?> <?php if (method_exists($this, 'beginPage')) $this->beginPage(); ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title><?php echo $title?></title> <title><?php echo $handler->htmlEncode($name); ?></title>
<style> <style>
body { body {
...@@ -51,8 +69,8 @@ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $excep ...@@ -51,8 +69,8 @@ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $excep
</head> </head>
<body> <body>
<h1><?php echo $title?></h1> <h1><?php echo $handler->htmlEncode($name); ?></h1>
<h2><?php echo nl2br($handler->htmlEncode($exception->getMessage()))?></h2> <h2><?php echo nl2br($handler->htmlEncode($message)); ?></h2>
<p> <p>
The above error occurred while the Web server was processing your request. The above error occurred while the Web server was processing your request.
</p> </p>
...@@ -60,7 +78,7 @@ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $excep ...@@ -60,7 +78,7 @@ $title = $handler->htmlEncode($exception instanceof \yii\base\Exception ? $excep
Please contact us if you think this is a server error. Thank you. Please contact us if you think this is a server error. Thank you.
</p> </p>
<div class="version"> <div class="version">
<?php echo date('Y-m-d H:i:s', time())?> <?php echo date('Y-m-d H:i:s', time()); ?>
</div> </div>
<?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?> <?php if (method_exists($this, 'endBody')) $this->endBody(); // to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment