Skip to content

Commit

Permalink
small modify
Browse files Browse the repository at this point in the history
  • Loading branch information
yidashi committed Jul 23, 2016
1 parent e4ca93d commit a914b3d
Show file tree
Hide file tree
Showing 382 changed files with 15,693 additions and 9,249 deletions.
35 changes: 13 additions & 22 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

# Urls
# ----
FRONTEND_URL = http:https://localhost:8080/
BACKEND_URL = http:https://localhost:8080/admin/
# Url美化
FRONTEND_PRETTY_URL = false
BACKEND_PRETTY_URL = false


# Mail
# ---------
Expand All @@ -34,30 +28,27 @@ MAIL_USERNAME=your_mail_username
MAIL_PASSWORD=your_mail_password
MAIL_ENCRYPTION=null


# Other
# -----

FRONTEND_COOKIE_VALIDATION_KEY=QYeL37kRMbCg1X9kmTzC3ctJqCVcqj1Y
BACKEND_COOKIE_VALIDATION_KEY=c0AXETckg6V4dYDAPlp0iQNgQHYhKXqM

ADMIN_EMAIL = [email protected]
ROBOT_EMAIL = [email protected]
FRONTEND_COOKIE_VALIDATION_KEY=<generated_key>
BACKEND_COOKIE_VALIDATION_KEY=<generated_key>

# 默认编辑器(redactor,markdown等)
EDITOR_TYPE = redactor

# Webuploader
# -------

STATIC_URL = http:https://localhost:8080/static
# Url美化
FRONTEND_PRETTY_URL = false
BACKEND_PRETTY_URL = false

WEBUPLOADER_DRIVER = local
# 如果driver = qiniu,则需要设置下边的配置
WEBUPLOADER_QINIU_DOMAIN = your-qiniu_domain
WEBUPLOADER_QINIU_BUCKET = your-qiniu_bucket
WEBUPLOADER_QINIU_ACCESS = your-qiniu_access
WEBUPLOADER_QINIU_SECRET = your-qiniu_secret
# Urls
# ----
SITE_URL = http:https://localhost:8080
FRONTEND_URL = http:https://localhost:8080
BACKEND_URL = http:https://localhost:8080/admin
// 上传文件访问地址
STORAGE_URL = http:https://localhost:8080/storage



Expand Down
23 changes: 23 additions & 0 deletions Yii.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
if (is_file(__DIR__ . '/.env')) {
(new \Dotenv\Dotenv(__DIR__))->load();
}

defined('YII_DEBUG') or define('YII_DEBUG', env('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', env('YII_ENV', 'prod'));

class Yii extends \yii\BaseYii
{
public static function getVersion()
{
return '0.1.0';
}
public static function powered()
{
return 'Powered by ' . '<a href="http:https://cms.51siyuan.cn/" rel="external">Yuan CMS</a>';
}
}

spl_autoload_register(['Yii', 'autoload'], true, true);
Yii::$classMap = require(__DIR__ . '/vendor/yiisoft/yii2/classes.php');
Yii::$container = new yii\di\Container();
3 changes: 2 additions & 1 deletion backend/assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
*/
class AppAsset extends AssetBundle
{
public $sourcePath = '@backend/assets';
public $sourcePath = '@backend/static';
public $css = [
'css/AdminLTE.min.css',
'css/site.css'
];
public $js = [
'js/app.min.js',
'js/notify.js',
'plugins/slimScroll/jquery.slimscroll.min.js'
];
public $depends = [
Expand Down
21 changes: 21 additions & 0 deletions backend/assets/AreaAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace backend\assets;

class AreaAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@backend/static';
public $css = [
'css/area.css',
];
public $js = [
'js/area.js'
];
public $depends = [
'backend\assets\AppAsset',
'backend\assets\HtmlSortableAsset'

];
public $jsOptions = array(
'position' => \yii\web\View::POS_END
);
}
14 changes: 14 additions & 0 deletions backend/assets/HtmlSortableAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace backend\assets;


class HtmlSortableAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@backend/static';
public $js = [
'js/html.sortable.js'
];
public $depends = [
'yii\web\JqueryAsset'
];
}
2 changes: 1 addition & 1 deletion backend/components/gii/crud/default/views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
}
?>

['class' => 'yii\grid\ActionColumn'],
['class' => 'backend\widgets\grid\ActionColumn'],
],
]); ?>
</div>
Expand Down
113 changes: 113 additions & 0 deletions backend/components/gii/model/Generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace backend\components\gii\model;

use Yii;
use yii\db\Schema;
use yii\base\NotSupportedException;


class Generator extends \yii\gii\generators\model\Generator
{
public $skipRuleColumns = ['created_at', 'updated_at'];

/**
* Generates validation rules for the specified table.
* @param \yii\db\TableSchema $table the table schema
* @return array the generated validation rules
*/
public function generateRules($table)
{
$types = [];
$lengths = [];
foreach ($table->columns as $column) {
if ($column->autoIncrement || in_array($column->name, $this->skipRuleColumns)) {
continue;
}
if (!$column->allowNull && $column->defaultValue === null) {
$types['required'][] = $column->name;
}
switch ($column->type) {
case Schema::TYPE_SMALLINT:
case Schema::TYPE_INTEGER:
case Schema::TYPE_BIGINT:
$types['integer'][] = $column->name;
break;
case Schema::TYPE_BOOLEAN:
$types['boolean'][] = $column->name;
break;
case Schema::TYPE_FLOAT:
case 'double': // Schema::TYPE_DOUBLE, which is available since Yii 2.0.3
case Schema::TYPE_DECIMAL:
case Schema::TYPE_MONEY:
$types['number'][] = $column->name;
break;
case Schema::TYPE_DATE:
case Schema::TYPE_TIME:
case Schema::TYPE_DATETIME:
case Schema::TYPE_TIMESTAMP:
$types['safe'][] = $column->name;
break;
default: // strings
if ($column->size > 0) {
$lengths[$column->size][] = $column->name;
} else {
$types['string'][] = $column->name;
}
}
}
$rules = [];
foreach ($types as $type => $columns) {
$rules[] = "[['" . implode("', '", $columns) . "'], '$type']";
}
foreach ($lengths as $length => $columns) {
$rules[] = "[['" . implode("', '", $columns) . "'], 'string', 'max' => $length]";
}

$db = $this->getDbConnection();

// Unique indexes rules
try {
$uniqueIndexes = $db->getSchema()->findUniqueIndexes($table);
foreach ($uniqueIndexes as $uniqueColumns) {
// Avoid validating auto incremental columns
if (!$this->isColumnAutoIncremental($table, $uniqueColumns)) {
$attributesCount = count($uniqueColumns);

if ($attributesCount === 1) {
$rules[] = "[['" . $uniqueColumns[0] . "'], 'unique']";
} elseif ($attributesCount > 1) {
$labels = array_intersect_key($this->generateLabels($table), array_flip($uniqueColumns));
$lastLabel = array_pop($labels);
$columnsList = implode("', '", $uniqueColumns);
$rules[] = "[['$columnsList'], 'unique', 'targetAttribute' => ['$columnsList'], 'message' => 'The combination of " . implode(', ', $labels) . " and $lastLabel has already been taken.']";
}
}
}
} catch (NotSupportedException $e) {
// doesn't support unique indexes information...do nothing
}

// Exist rules for foreign keys
foreach ($table->foreignKeys as $refs) {
$refTable = $refs[0];
$refTableSchema = $db->getTableSchema($refTable);
if ($refTableSchema === null) {
// Foreign key could point to non-existing table: https://github.com/yiisoft/yii2-gii/issues/34
continue;
}
$refClassName = $this->generateClassName($refTable);
unset($refs[0]);
$attributes = implode("', '", array_keys($refs));
$targetAttributes = [];
foreach ($refs as $key => $value) {
$targetAttributes[] = "'$key' => '$value'";
}
$targetAttributes = implode(', ', $targetAttributes);
$rules[] = "[['$attributes'], 'exist', 'skipOnError' => true, 'targetClass' => $refClassName::className(), 'targetAttribute' => [$targetAttributes]]";
}

return $rules;
}

}
99 changes: 99 additions & 0 deletions backend/components/gii/model/default/model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* This is the template for generating the model class of a specified table.
*/

/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\model\Generator */
/* @var $tableName string full table name */
/* @var $className string class name */
/* @var $queryClassName string query class name */
/* @var $tableSchema yii\db\TableSchema */
/* @var $labels string[] list of attribute labels (name => label) */
/* @var $rules string[] list of validation rules */
/* @var $relations array list of relations (name => relation declaration) */

echo "<?php\n";
?>

namespace <?= $generator->ns ?>;

use Yii;

/**
* This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
*
<?php foreach ($tableSchema->columns as $column): ?>
* @property <?= "{$column->phpType} \${$column->name}\n" ?>
<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
<?php foreach ($relations as $name => $relation): ?>
* @property <?= $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n" ?>
<?php endforeach; ?>
<?php endif; ?>
*/
class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') . "\n" ?>
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '<?= $generator->generateTableName($tableName) ?>';
}
<?php if ($generator->db !== 'db'): ?>

/**
* @return \yii\db\Connection the database connection used by this AR class.
*/
public static function getDb()
{
return Yii::$app->get('<?= $generator->db ?>');
}
<?php endif; ?>

/**
* @inheritdoc
*/
public function rules()
{
return [<?= "\n " . implode(",\n ", $rules) . ",\n " ?>];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
<?php foreach ($labels as $name => $label): ?>
<?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?>
];
}
<?php foreach ($relations as $name => $relation): ?>

/**
* @return \yii\db\ActiveQuery
*/
public function get<?= $name ?>()
{
<?= $relation[0] . "\n" ?>
}
<?php endforeach; ?>
<?php if ($queryClassName): ?>
<?php
$queryClassFullName = ($generator->ns === $generator->queryNs) ? $queryClassName : '\\' . $generator->queryNs . '\\' . $queryClassName;
echo "\n";
?>
/**
* @inheritdoc
* @return <?= $queryClassFullName ?> the active query used by this AR class.
*/
public static function find()
{
return new <?= $queryClassFullName ?>(get_called_class());
}
<?php endif; ?>
}
Loading

0 comments on commit a914b3d

Please sign in to comment.