Commit a0f90ce3 authored by xiabin's avatar xiabin

修改结构

parent db5d2a32
The Yii framework is free software. It is released under the terms of
the following BSD License.
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Yii 2 Advanced Project Template
===============================
Yii 2 Advanced Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
developing complex Web applications with multiple tiers.
The template includes three tiers: front end, back end, and console, each of which
is a separate Yii application.
The template is designed to work in a team development environment. It supports
deploying the application in different environments.
Documentation is at [docs/guide/README.md](docs/guide/README.md).
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-app-advanced/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-app-advanced)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-app-advanced/downloads.png)](https://packagist.org/packages/yiisoft/yii2-app-advanced)
[![Build Status](https://travis-ci.org/yiisoft/yii2-app-advanced.svg?branch=master)](https://travis-ci.org/yiisoft/yii2-app-advanced)
DIRECTORY STRUCTURE
-------------------
```
common
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
console
config/ contains console configurations
controllers/ contains console controllers (commands)
migrations/ contains database migrations
models/ contains console-specific model classes
runtime/ contains files generated during runtime
backend
assets/ contains application assets such as JavaScript and CSS
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
views/ contains view files for the Web application
web/ contains the entry script and Web resources
frontend
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
views/ contains view files for the Web application
web/ contains the entry script and Web resources
widgets/ contains frontend widgets
vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
tests contains various tests for the advanced application
codeception/ contains tests developed with Codeception PHP Testing Framework
```
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
main-local.php
params-local.php
\ No newline at end of file
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
<?php
return [
'adminEmail' => 'admin@example.com',
];
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
/**
* Site controller
*/
class SiteController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
/**
* Login action.
*
* @return string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
/**
* Logout action.
*
* @return string
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
}
*
!.gitignore
\ No newline at end of file
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link']
)
. Html::endForm()
. '</li>';
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */
use yii\helpers\Html;
$this->title = $name;
?>
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= 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>
<?php
/* @var $this yii\web\View */
$this->title = 'My Yii Application';
?>
<div class="site-index">
<div class="jumbotron">
<h1>Congratulations!</h1>
<p class="lead">You have successfully created your Yii-powered application.</p>
<p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
</div>
<div class="body-content">
<div class="row">
<div class="col-lg-4">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/forum/">Yii Forum &raquo;</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/extensions/">Yii Extensions &raquo;</a></p>
</div>
</div>
</div>
</div>
<?php
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
/index.php
/index-test.php
html,
body {
height: 100%;
}
.wrap {
min-height: 100%;
height: auto;
margin: 0 auto -60px;
padding: 0 0 60px;
}
.wrap > .container {
padding: 70px 15px 20px;
}
.footer {
height: 60px;
background-color: #f5f5f5;
border-top: 1px solid #ddd;
padding-top: 20px;
}
.jumbotron {
text-align: center;
background-color: transparent;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.not-set {
color: #c55;
font-style: italic;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after {
content: /*"\e113"*/ "\e151";
}
a.desc:after {
content: /*"\e114"*/ "\e152";
}
.sort-numerical a.asc:after {
content: "\e153";
}
.sort-numerical a.desc:after {
content: "\e154";
}
.sort-ordinal a.asc:after {
content: "\e155";
}
.sort-ordinal a.desc:after {
content: "\e156";
}
.grid-view td {
white-space: nowrap;
}
.grid-view .filters input,
.grid-view .filters select {
min-width: 50px;
}
.hint-block {
display: block;
margin-top: 5px;
color: #999;
}
.error-summary {
color: #a94442;
background: #fdf7f7;
border-left: 3px solid #eed3d7;
padding: 10px 20px;
margin: 0 0 15px 0;
}
/* align the logout "link" (button in form) of the navbar */
.nav > li > form {
padding: 8px;
}
@media(max-width:768px) {
.nav li > form {
padding: 3px;
}
}
.nav > li > form > button:hover {
text-decoration: none;
}
User-agent: *
Disallow: /
main-local.php
params-local.php
<?php
Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
<?php
return [
'name' => 'zuiketang',
'language' => 'zh-CN',
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'bootstrap' => ['log'],
'components' => [
'cache' => [
'class' => 'yii\redis\Cache',
'redis' => [
'hostname' => '192.168.1.185',
'port' => 6379,
'database' => 0,
]
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=192.168.1.185;dbname=zuiketang',
'username' => 'root',
'password' => 'mysql123',
'charset' => 'utf8',
],
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => '192.168.1.185',
'port' => 6379,
'database' => 0,
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => TRUE,
],
'authManager' => [
'class' => 'yii\rbac\PhpManager',
'defaultRoles' => ['normal', 'teacher'],
],
'urlManager' => [
'enablePrettyUrl' => TRUE,
'enableStrictParsing' => FALSE,
'showScriptName' => FALSE,
'rules' => [
'<controller:\w+>s' => '<controller>/index',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
],
],
],
];
<?php
return [
'adminEmail' => 'admin@example.com',
'supportEmail' => 'support@example.com',
'user.passwordResetTokenExpire' => 3600,
'captchaId' => '4d6ad870bf63a30be3d22c92925b04ca',
'privateKey' => 'a2ca5e5139d1f43ac4e1cd248f3e52e4',
'msg.host' => 'http://114.55.132.75:7893/sms.aspx',
'msg.userid' => '78',
'msg.account' => '276147613x',
'msg.password' => '276147613',
'msg.signature' => '【最课堂】'
];
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/26
* Time: 下午6:18
*/
namespace common\libs;
use Yii;
use \GuzzleHttp\Client;
use yii\log\Logger;
/**
* Class Message
* @package common\libs
*/
class Message
{
public $hosts;
public $query;
public $httpClient;
public function __construct()
{
$params = Yii::$app->params;
$this->hosts = $params['msg.host'];
$this->query = [
'action' => 'send',
'userid' => $params['msg.userid'],
'account' => $params['msg.account'],
'password' => $params['msg.password'],
];
$this->httpClient = new Client();
}
/**
* @param $telephones
* @param $content
* @return mixed|\Psr\Http\Message\ResponseInterface
* @throws \Exception
*/
public function send($telephones, $content)
{
if (is_array($telephones)) {
$telephones = implode(',', $telephones);
}
$content .= ' ' . Yii::$app->params['msg.signature'];
$this->query['mobile'] = $telephones;
$this->query['content'] = $content;
try {
$response = $this->httpClient->request('GET', $this->hosts, [
'form_params' => $this->query
]);
} catch (ClientException $e) {
$response = $e->getResponse();
} catch (\Exception $e) {
throw $e;
Yii::getLogger()->log($e, Logger::LEVEL_ERROR, 'Message');
}
$return = new \SimpleXMLElement($response->getBody()->getContents());
if ((string)$return->returnstatus !== 'Success') {
Yii::getLogger()->log((string)$return->message, Logger::LEVEL_ERROR, 'Message');
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 2016/9/26
* Time: 下午6:46
*/
namespace common\libs;
use yii\web\Response;
class Utils
{
/**
* 获取real IP
* @return string
*/
public static function getRealIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif (!empty($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = '';
preg_match('/[\d\.]{7,15}/', $ip, $ips);
return !empty($ips[0]) ? $ips[0] : '';
}
/**
* @param bool $status
* @param null $data
* @param null $messgae
*/
public static function ajaxResponse($status = TRUE, $messgae = NULL, $data = NULL)
{
$response = \Yii::$app->response;
$response->format = Response::FORMAT_JSON;
$response->data = [
'status' => $status,
'data' => $data,
'message' => $messgae
];
}
/**
* 生成4-6位随机数
* @param int $length
* @return int
*/
public static function randomNumber($length = 6)
{
if ($length < 4 or $length > 6) {
$length = 6;
}
switch ($length) {
case 4:
$min = 1000;
$max = 9999;
break;
case 5:
$min = 10000;
$max = 99999;
break;
case 6:
$min = 100000;
$max = 999999;
break;
}
return mt_rand($min, $max);
}
/**
* 判断是否为手机号码
* @param $telephone
* @return bool
*/
public static function isTelephone($telephone)
{
if (preg_match('/^1[34578]{1}\d{9}$/', $telephone)) {
return TRUE;
} else {
return FALSE;
}
}
}
\ No newline at end of file
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
<?php $this->endPage() ?>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
<div class="password-reset">
<p>Hello <?= Html::encode($user->username) ?>,</p>
<p>Follow the link below to reset your password:</p>
<p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p>
</div>
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
Hello <?= $user->username ?>,
Follow the link below to reset your password:
<?= $resetLink ?>
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "browse_record".
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $time
*/
class BrowseRecord extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'browse_record';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'course_id', 'time'], 'required'],
[['user_id', 'course_id', 'time'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'time' => 'Time',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "classes".
*
* @property integer $id
* @property integer $user_id
* @property string $id_number
* @property string $id_name
* @property string $name
* @property string $intro
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*/
class Classes extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'classes';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'id_number', 'id_name', 'name', 'intro', 'created_at', 'updated_at'], 'required'],
[['user_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['intro'], 'string'],
[['id_number', 'id_name', 'name'], 'string', 'max' => 64],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'id_number' => 'Id Number',
'id_name' => 'Id Name',
'name' => 'Name',
'intro' => 'Intro',
'status' => '0 未审核 1 审核通过 2 审核不通过 3 锁定 ',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "classes_teacher".
*
* @property integer $class_id
* @property integer $teacher_id
*/
class ClassesTeacher extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'classes_teacher';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['class_id', 'teacher_id'], 'required'],
[['class_id', 'teacher_id'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'class_id' => 'Class ID',
'teacher_id' => 'Teacher ID',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "comments".
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $parent_id
* @property string $content
* @property string $ip
* @property integer $created_at
*/
class Comments extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'comments';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'course_id', 'parent_id', 'content', 'ip', 'created_at'], 'required'],
[['user_id', 'course_id', 'parent_id', 'created_at'], 'integer'],
[['content'], 'string'],
[['ip'], 'string', 'max' => 32],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'parent_id' => 'Parent ID',
'content' => 'Content',
'ip' => 'Ip',
'created_at' => 'Created At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "consume".
*
* @property integer $id
* @property integer $user_id
* @property integer $orders_id
*/
class Consume extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'consume';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'orders_id'], 'required'],
[['user_id', 'orders_id'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'orders_id' => 'Orders ID',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "courseware".
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $type
* @property string $name
* @property integer $status
* @property string $size
* @property string $time
* @property string $format
* @property integer $created_at
* @property integer $updated_at
*/
class Courseware extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'courseware';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'course_id', 'name', 'size', 'time', 'format', 'created_at', 'updated_at'], 'required'],
[['user_id', 'course_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
[['name'], 'string', 'max' => 128],
[['size', 'time'], 'string', 'max' => 32],
[['format'], 'string', 'max' => 16],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'type' => '课件类型 默认0',
'name' => 'Name',
'status' => '0 未审核 1 审核通过 2 审核不通过 3 锁定 ',
'size' => '文件大小 kb',
'time' => '视频时间 秒',
'format' => '格式',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "favorite".
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property integer $created_at
*/
class Favorite extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'favorite';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'course_id', 'created_at'], 'required'],
[['user_id', 'course_id', 'created_at'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'created_at' => 'Created At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "income".
*
* @property integer $id
* @property integer $user_id
* @property integer $orders_id
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
*/
class Income extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'income';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'orders_id', 'created_at', 'updated_at'], 'required'],
[['user_id', 'orders_id', 'status', 'created_at', 'updated_at'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'orders_id' => 'Orders ID',
'status' => '0 未结算 1 结算 ',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "member".
*
* @property integer $id
* @property integer $user_id
* @property integer $member_id
* @property integer $type
* @property integer $created_at
* @property integer $updated_at
*/
class Member extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'member';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'member_id', 'type', 'created_at', 'updated_at'], 'required'],
[['user_id', 'member_id', 'type', 'created_at', 'updated_at'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'member_id' => 'Member ID',
'type' => '会员类型 0 未付费 1 付费',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "orders".
*
* @property integer $id
* @property integer $user_id
* @property integer $course_id
* @property string $number
* @property string $credit
* @property integer $status
* @property string $pay_order
* @property integer $created_at
* @property integer $updated_at
*/
class Orders extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'orders';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'course_id', 'number', 'credit', 'pay_order', 'created_at', 'updated_at'], 'required'],
[['user_id', 'course_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['number', 'credit'], 'string', 'max' => 32],
[['pay_order'], 'string', 'max' => 64],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'course_id' => 'Course ID',
'number' => 'Number',
'credit' => '消费',
'status' => '0 未支付 1 已支付',
'pay_order' => '第三方支付订单',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "support".
*
* @property integer $id
* @property integer $user_id
* @property integer $courseware_id
* @property integer $created_at
*/
class Support extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'support';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'courseware_id', 'created_at'], 'required'],
[['user_id', 'courseware_id', 'created_at'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'courseware_id' => 'Courseware ID',
'created_at' => 'Created At',
];
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "teacher".
*
* @property integer $id
* @property integer $user_id
* @property string $name
* @property string $avatar
* @property string $intro
* @property integer $created_at
* @property integer $updated_at
*/
class Teacher extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'teacher';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'name', 'avatar', 'intro', 'created_at', 'updated_at'], 'required'],
[['user_id', 'created_at', 'updated_at'], 'integer'],
[['intro'], 'string'],
[['name'], 'string', 'max' => 64],
[['avatar'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'name' => 'Name',
'avatar' => 'Avatar',
'intro' => 'Intro',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* This is the model class for table "user".
*
* @property integer $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property string $password_reset_token
* @property string $telephone
* @property integer $role
* @property integer $status
* @property string $avatar
* @property string $wx_open_id
* @property string $ip
* @property string $created_at
* @property string $updated_at
* @property string $logged_at
*
* @property BrowseRecord[] $browseRecords
* @property Classes[] $classes
* @property Collection[] $collections
* @property Comments[] $comments
* @property Consume[] $consumes
* @property Income[] $incomes
* @property Orders[] $orders
* @property Support[] $supports
* @property Teacher[] $teachers
* @property Weixin[] $weixins
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_ACTIVE = 0;
const STATUS_OTHER = 1;
const ROLE_NORMAL = 0;//正常
const ROLE_TEACHER = 1;//讲师
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%users}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
// if you're using datetime instead of UNIX timestamp:
// 'value' => new Expression('NOW()'),
],];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'auth_key', 'password_hash', 'telephone', 'ip', 'logged_at'], 'required'],
[['role', 'status'], 'integer'],
[['created_at', 'updated_at', 'logged_at'], 'safe'],
[['username', 'auth_key', 'wx_open_id', 'ip'], 'string', 'max' => 32],
[['password_hash'], 'string', 'max' => 255],
['password_reset_token', 'string', 'max' => 32],
[['telephone'], 'string', 'max' => 15],
[['avatar'], 'string', 'max' => 128],
['status', 'default', 'value' => self::STATUS_ACTIVE],
['role', 'default', 'value' => self::ROLE_NORMAL],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'id',
'username' => 'username',
'auth_key' => 'Auth Key',
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'telephone' => 'telephone',
'role' => 'role 0 ',
'status' => 'status 0 ',
'avatar' => 'avatar',
'wx_open_id' => 'wx_open_id',
'ip' => 'ip',
'created_at' => 'created_at',
'updated_at' => 'updated_at',
'logged_at' => 'logged_at',
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = NULL)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $telephone
* @return static|null
*/
public static function findByTelephone($telephone)
{
return static::findOne(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE]);
}
public static function findByTelephone2($telephone)
{
// return static::findOne(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE]);
return static::find()->select('id,username')->where(['telephone' => $telephone, 'status' => self::STATUS_ACTIVE])
->one();
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return NULL;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return FALSE;
}
$timestamp = (int)substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = (string)mt_rand(100000, 999999) . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = '';
}
}
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "weixin".
*
* @property integer $id
* @property integer $user_id
* @property string $name
* @property string $avatar
* @property string $open_id
* @property integer $created_at
* @property integer $updated_at
*/
class Weixin extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'weixin';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'name', 'avatar', 'open_id', 'created_at', 'updated_at'], 'required'],
[['user_id', 'created_at', 'updated_at'], 'integer'],
[['name'], 'string', 'max' => 64],
[['avatar'], 'string', 'max' => 255],
[['open_id'], 'string', 'max' => 32],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'name' => 'Name',
'avatar' => 'Avatar',
'open_id' => 'Open ID',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace common\widgets;
use Yii;
/**
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* ```php
* Yii::$app->session->setFlash('error', 'This is the message');
* Yii::$app->session->setFlash('success', 'This is the message');
* Yii::$app->session->setFlash('info', 'This is the message');
* ```
*
* Multiple messages could be set as follows:
*
* ```php
* Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']);
* ```
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
*/
class Alert extends \yii\bootstrap\Widget
{
/**
* @var array the alert types configuration for the flash messages.
* This array is setup as $key => $value, where:
* - $key is the name of the session flash variable
* - $value is the bootstrap alert type (i.e. danger, success, info, warning)
*/
public $alertTypes = [
'error' => 'alert-danger',
'danger' => 'alert-danger',
'success' => 'alert-success',
'info' => 'alert-info',
'warning' => 'alert-warning'
];
/**
* @var array the options for rendering the close button tag.
*/
public $closeButton = [];
public function init()
{
parent::init();
$session = Yii::$app->session;
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data) {
if (isset($this->alertTypes[$type])) {
$data = (array) $data;
foreach ($data as $i => $message) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
}
}
}
{
"name": "zuiketang",
"description": "zuiketang",
"keywords": [
"zuiketang"
],
"homepage": "http://www.yiiframework.com/",
"support": {
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.6",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-redis": "^2.0",
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*"
},
"config": {
"process-timeout": 1800
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
},
"scripts": {
"post-install-cmd": "php init --env=Development --overwrite=n"
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
}
This diff is collapsed.
main-local.php
params-local.php
\ No newline at end of file
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
];
<?php
return [
'adminEmail' => 'admin@example.com',
];
<?php
/**
* Created by PhpStorm.
* User: xiabin
* Date: 16/9/24
* Time: 上午9:50
*/
namespace console\controllers;
use Yii;
use \yii\console\Controller;
class RbacController extends Controller
{
public function actionInit()
{
$rule = new \frontend\rbac\UserGroupRule();
$auth = Yii::$app->authManager;
$auth->add($rule);
// 添加 "author" 角色并赋予 "createPost" 权限
$normal = $auth->createRole('normal');
$normal->ruleName = $rule->name;
$auth->add($normal);
// 和 "author" 权限
$teahcer = $auth->createRole('teacher');
$teahcer->ruleName = $rule->name;
$auth->add($teahcer);
$auth->addChild($teahcer, $normal);
}
}
\ No newline at end of file
<?php
use yii\db\Migration;
class m160927_104153_users_init extends Migration
{
public $table = '{{%users}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'username' => $this->string()->notNull()->unique(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string(64)->defaultValue(''),
'telephone' => $this->string(15)->notNull()->unique(),
'role' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 普通 1 讲师'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 正常 1 锁定'),
'avatar' => $this->string(128)->notNull()->defaultValue(''),
'wx_open_id' => $this->string(32)->defaultValue('')->comment('登录微信id'),
'ip' => $this->string(32)->notNull(),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
'logged_at' => $this->integer()->notNull()
], $tableOptions);
$this->createIndex('index-id-status', $this->table, ['id', 'status'], TRUE);
$this->createIndex('index-wx_open_id', $this->table, 'wx_open_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_113951_weixin_init extends Migration
{
public $table = '{{%weixin}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'name' => $this->string(64)->notNull(),
'avatar' => $this->string(255)->notNull(),
'open_id' => $this->string(32)->notNull(''),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户绑定微信表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_114841_browse_record_init extends Migration
{
public $table = '{{%browse_record}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'time' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '浏览记录表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_115114_classes_init extends Migration
{
public $table = '{{%classes}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'id_number' => $this->string(64)->notNull(),
'id_name' => $this->string(64)->notNull(),
'name' => $this->string(64)->notNull(),
'intro' => $this->text()->notNull(),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户课堂表');
$this->createIndex('index-user_id-status', $this->table, ['user_id', 'status']);
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_115425_classes_teacher_init extends Migration
{
public $table = '{{%classes_teacher}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'class_id' => $this->integer()->notNull()->unsigned(),
'teacher_id' => $this->integer()->notNull()->unsigned(),
], $tableOptions);
$this->addCommentOnTable($this->table, '讲师课堂关系表');
$this->addPrimaryKey(
'pk',
$this->table,
['class_id', 'teacher_id']
);
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_120435_favorite_init extends Migration
{
public $table = '{{%favorite}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'created_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '收藏表');
$this->createIndex('index-course_id', $this->table, 'course_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_120550_comments_init extends Migration
{
public $table = '{{%comments}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'parent_id' => $this->integer()->notNull()->unsigned(),
'content' => $this->text()->notNull(),
'ip' => $this->string(32)->notNull(),
'created_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '评论表');
$this->createIndex('index-course_id', $this->table, 'course_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_120953_consume_init extends Migration
{
public $table = '{{%consume}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'orders_id' => $this->integer()->notNull()->unsigned(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户消费表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_121107_course_init extends Migration
{
public $table = '{{%course}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'classed_id' => $this->integer()->notNull()->unsigned(),
'avatar' => $this->string(255)->notNull(),
'name' => $this->string(32)->notNull(),
'price' => $this->integer()->notNull(),
'free_time' => $this->integer()->notNull(),
'intro' => $this->text()->notNull(),
'preview_pic' => $this->string(255)->notNull(),
'recommend' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 表示推荐 1推荐'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->createIndex(
'index-user_id-status',
$this->table,
['user_id', 'status'],
FALSE
);
$this->addCommentOnTable($this->table, '用户课程表');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_121625_courseware_init extends Migration
{
public $table = '{{%courseware}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'type' => $this->smallInteger()->notNull()->defaultValue(0)->unsigned()->comment('课件类型 默认0'),
'name' => $this->string(128)->notNull(),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'size' => $this->string(32)->notNull()->comment('文件大小 kb'),
'time' => $this->string(32)->notNull()->comment('视频时间 秒'),
'format' => $this->string(16)->notNull()->comment('格式'),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户课件表');
$this->createIndex('index-course_id', $this->table, 'course_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_122057_income_init extends Migration
{
public $table = '{{%income}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'orders_id' => $this->integer()->notNull()->unsigned(),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未结算 1 结算 '),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户收入表');
$this->createIndex('index-user_id-status', $this->table, ['user_id', 'status']);
$this->createIndex('index-orders_id', $this->table, 'orders_id');
}
public function down()
{
echo "m160927_113951_winxin_init cannot be reverted.\n";
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_122231_orders_init extends Migration
{
public $table = '{{%orders}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'course_id' => $this->integer()->notNull()->unsigned(),
'number' => $this->string(32)->notNull(),
'credit' => $this->string(32)->notNull()->comment('消费'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->unsigned()->comment('0 未支付 1 已支付'),
'pay_order' => $this->string(64)->notNull()->comment('第三方支付订单'),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户订单表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
echo "m160927_113951_winxin_init cannot be reverted.\n";
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_122734_support_init extends Migration
{
public $table = '{{%support}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'courseware_id' => $this->integer()->notNull()->unsigned(),
'created_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户点赞表');
$this->createIndex('index-courseware_id', $this->table, 'courseware_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_122843_teacher_init extends Migration
{
public $table = '{{%teacher}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'name' => $this->string(64)->notNull(),
'avatar' => $this->string(255)->notNull(),
'intro' => $this->text()->notNull(''),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '讲师表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
use yii\db\Migration;
class m160927_123009_member_init extends Migration
{
public $table = '{{%member}}';
public function up()
{
$tableOptions = NULL;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'member_id' => $this->integer()->notNull()->unsigned(),
'type' => $this->smallInteger()->notNull()->unsigned()->comment('会员类型 0 未付费 1 付费'),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
$this->addCommentOnTable($this->table, '用户会员表');
$this->createIndex('index-user_id', $this->table, 'user_id');
}
public function down()
{
echo "m160927_113951_winxin_init cannot be reverted.\n";
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
return [
'normal' => [
'type' => 1,
'ruleName' => 'userGroup',
],
'teacher' => [
'type' => 1,
'ruleName' => 'userGroup',
'children' => [
'normal',
],
],
];
<?php
return [
'userGroup' => 'O:27:"frontend\\rbac\\UserGroupRule":3:{s:4:"name";s:9:"userGroup";s:9:"createdAt";N;s:9:"updatedAt";N;}',
];
*
!.gitignore
\ No newline at end of file
<?php
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
<?php
// NOTE: Make sure this file is not accessible when deployed to production
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
die('You are not allowed to access this file.');
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = require(__DIR__ . '/../../tests/codeception/config/backend/acceptance.php');
(new yii\web\Application($config))->run();
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
<?php
return [
// 'components' => [
// 'db' => [
// 'class' => 'yii\db\Connection',
// 'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
// 'username' => 'root',
// 'password' => '',
// 'charset' => 'utf8',
// ],
// 'mailer' => [
// 'class' => 'yii\swiftmailer\Mailer',
// 'viewPath' => '@common/mail',
// // send all mails to a file by default. You have to set
// // 'useFileTransport' to false and configure a transport
// // for the mailer to send real emails.
// 'useFileTransport' => true,
// ],
// ],
];
<?php
return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
],
];
<?php
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '1o1zEUf8jdBvsnZy_JygPUO5_sZ7zBci',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
<?php
// NOTE: Make sure this file is not accessible when deployed to production
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
die('You are not allowed to access this file.');
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = require(__DIR__ . '/../../tests/codeception/config/frontend/acceptance.php');
(new yii\web\Application($config))->run();
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
<?php
return [
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
],
];
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/console/config/main.php'),
require(__DIR__ . '/console/config/main-local.php')
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
<?php
/**
* The manifest of files that are local to specific environment.
* This file returns a list of environments that the application
* may be installed under. The returned data must be in the following
* format:
*
* ```php
* return [
* 'environment name' => [
* 'path' => 'directory storing the local files',
* 'skipFiles' => [
* // list of files that should only copied once and skipped if they already exist
* ],
* 'setWritable' => [
* // list of directories that should be set writable
* ],
* 'setExecutable' => [
* // list of files that should be set executable
* ],
* 'setCookieValidationKey' => [
* // list of config files that need to be inserted with automatically generated cookie validation keys
* ],
* 'createSymlink' => [
* // list of symlinks to be created. Keys are symlinks, and values are the targets.
* ],
* ],
* ];
* ```
*/
return [
'Development' => [
'path' => 'dev',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
],
'setExecutable' => [
'yii',
'tests/codeception/bin/yii',
],
'setCookieValidationKey' => [
'backend/config/main-local.php',
'frontend/config/main-local.php',
],
],
'Production' => [
'path' => 'prod',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
],
'setExecutable' => [
'yii',
],
'setCookieValidationKey' => [
'backend/config/main-local.php',
'frontend/config/main-local.php',
],
],
];
<?php
return [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
],
];
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
],
],
];
<?php
return [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
],
];
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
<?php
return [
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_tests',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
],
];
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/console/config/main.php'),
require(__DIR__ . '/console/config/main-local.php')
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
use yii\web\View;
use Yii;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot/assets';
public $baseUrl = '@web/assets';
public $css = [
'css/site.css',
];
public $js = [
['common/common.js', 'position' => View::POS_BEGIN]
];
public $depends = [
// 'yii\web\YiiAsset',
// 'yii\bootstrap\BootstrapAsset',
];
//定义按需加载JS方法,注意加载顺序在最后
public static function addScript($view, $jsfile)
{
$jsfile = self::appendTimestamp($jsfile);
$view->registerJsFile($jsfile, [AppAsset::className(), 'depends' => 'frontend\assets\AppAsset']);
}
//定义按需加载css方法,注意加载顺序在最后
public static function addCss($view, $cssfile)
{
$cssfile = self::appendTimestamp($cssfile);
$view->registerCssFile($cssfile, [AppAsset::className(), 'depends' => 'frontend\assets\AppAsset']);
}
public static function appendTimestamp($url)
{
if (Yii::$app->assetManager->appendTimestamp && strncmp($url, '@web/', 5) === 0) {
$fileToCacheBust = Yii::getAlias(str_replace('@web', '@webroot', $url));
if (($timestamp = @filemtime("$fileToCacheBust")) > 0)
$url .= "?v={$timestamp}";
}
return $url;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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