diff --git a/backend/widgets/ActiveField.php b/backend/widgets/ActiveField.php
new file mode 100644
index 00000000..15dd9bc2
--- /dev/null
+++ b/backend/widgets/ActiveField.php
@@ -0,0 +1,37 @@
+adjustLabelFor($options);
+ $this->parts['{input}'] = Html::activeStaticControl($this->model, $this->attribute, $options);
+ return $this;
+ }
+
+ public function suffix($suffix = '', $suffixType = 'addon', $size = 300)
+ {
+ $size = !empty($size) ? "input-group-{$size} " : '';
+ $this->template = "{label}\n
\n{hint}\n{error}";
+ return $this;
+ }
+
+ public function prefix($prefix = '', $prefixType = 'addon', $size = 300)
+ {
+ $size = !empty($size) ? "input-group-{$size} " : '';
+ $this->template = "{label}\n\n{hint}\n{error}";
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/backend/widgets/ActiveForm.php b/backend/widgets/ActiveForm.php
index 58fada9c..09e902e6 100755
--- a/backend/widgets/ActiveForm.php
+++ b/backend/widgets/ActiveForm.php
@@ -9,9 +9,11 @@
namespace backend\widgets;
use yii\helpers\ArrayHelper;
+use yii\base\Model;
class ActiveForm extends \yii\widgets\ActiveForm
{
+ public $fieldClass = 'backend\widgets\ActiveField';
public $boxFieldClass = '\backend\widgets\BoxField';
/**
@@ -38,56 +40,19 @@ public function boxField($model, $attribute, $options = [])
}
/**
- * 有后缀的
- * @param $model
- * @param $attribute
- * @param string $suffix
- * @param string $suffixType
- * @param array $options
- * @return object
+ * Generates a form field.
+ * A form field is associated with a model and an attribute. It contains a label, an input and an error message
+ * and use them to interact with end users to collect their inputs for the attribute.
+ * @param Model $model the data model.
+ * @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
+ * about attribute expression.
+ * @param array $options the additional configurations for the field object. These are properties of [[ActiveField]]
+ * or a subclass, depending on the value of [[fieldClass]].
+ * @return ActiveField the created ActiveField object.
+ * @see fieldConfig
*/
- public function suffixField($model, $attribute, $suffix = '', $suffixType = 'addon', $options = [])
+ public function field($model, $attribute, $options = [])
{
- $config = $this->fieldConfig;
- if ($config instanceof \Closure) {
- $config = call_user_func($config, $model, $attribute);
- }
- if (!isset($config['class'])) {
- $config['class'] = $this->fieldClass;
- }
- $defaultOptions = ['template' => "{label}\n\n{hint}\n{error}"];
- $options = array_merge($defaultOptions, $options);
- return \Yii::createObject(ArrayHelper::merge($config, $options, [
- 'model' => $model,
- 'attribute' => $attribute,
- 'form' => $this,
- ]));
- }
-
- /**
- * 有前缀的
- * @param $model
- * @param $attribute
- * @param string $prefix
- * @param string $prefixType
- * @param array $options
- * @return object
- */
- public function prefixField($model, $attribute, $prefix = '', $prefixType = 'addon', $options = [])
- {
- $config = $this->fieldConfig;
- if ($config instanceof \Closure) {
- $config = call_user_func($config, $model, $attribute);
- }
- if (!isset($config['class'])) {
- $config['class'] = $this->fieldClass;
- }
- $defaultOptions = ['template' => "{label}\n\n{hint}\n{error}"];
- $options = array_merge($defaultOptions, $options);
- return \Yii::createObject(ArrayHelper::merge($config, $options, [
- 'model' => $model,
- 'attribute' => $attribute,
- 'form' => $this,
- ]));
+ return parent::field($model, $attribute, $options);
}
}
\ No newline at end of file
diff --git a/backend/widgets/BoxField.php b/backend/widgets/BoxField.php
index 57ab36f6..31bb08b6 100755
--- a/backend/widgets/BoxField.php
+++ b/backend/widgets/BoxField.php
@@ -2,9 +2,8 @@
namespace backend\widgets;
use yii\helpers\Html;
-use yii\widgets\ActiveField;
-class BoxField extends ActiveField
+class BoxField extends \yii\widgets\ActiveField
{
public $collapsed = false;
diff --git a/common/helpers/Html.php b/common/helpers/Html.php
index dc7ff0a7..3a40fe32 100755
--- a/common/helpers/Html.php
+++ b/common/helpers/Html.php
@@ -20,6 +20,30 @@ public static function icon($name)
return self::tag('i', '', $options);
}
+ public static function staticControl($value, $options = [])
+ {
+ static::addCssClass($options, 'form-control-static');
+ $value = (string) $value;
+ if (isset($options['encode'])) {
+ $encode = $options['encode'];
+ unset($options['encode']);
+ } else {
+ $encode = true;
+ }
+ return static::tag('p', $encode ? static::encode($value) : $value, $options);
+ }
+
+ public static function activeStaticControl($model, $attribute, $options = [])
+ {
+ if (isset($options['value'])) {
+ $value = $options['value'];
+ unset($options['value']);
+ } else {
+ $value = static::getAttributeValue($model, $attribute);
+ }
+ return static::staticControl($value, $options);
+ }
+
/**
* 标红字符串中含有的关键词
* @param $q string 关键词
diff --git a/common/modules/book/Module.php b/common/modules/book/Module.php
new file mode 100644
index 00000000..066a4b89
--- /dev/null
+++ b/common/modules/book/Module.php
@@ -0,0 +1,31 @@
+id == 'app-backend') {
+ $app->urlManager->addRules([
+ 'book/' => 'book/admin/',
+ ], false);
+ } else if ($app->id == 'app-frontend') {
+ $app->urlManager->addRules([
+ 'books' => '/book/default/index',
+ 'book/' => '/book/default/view',
+ 'book/chapter/' => '/book/default/chapter',
+ 'book/' => 'book/default/',
+ ], false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/backend/controllers/BookController.php b/common/modules/book/controllers/AdminController.php
similarity index 94%
rename from backend/controllers/BookController.php
rename to common/modules/book/controllers/AdminController.php
index 3879dc63..66a89950 100644
--- a/backend/controllers/BookController.php
+++ b/common/modules/book/controllers/AdminController.php
@@ -6,19 +6,17 @@
* Time: 下午2:05
*/
-namespace backend\controllers;
+namespace common\modules\book\controllers;
use backend\actions\Position;
-use common\models\Book;
-use common\models\BookChapter;
-use yii\base\InvalidParamException;
+use common\modules\book\models\Book;
+use common\modules\book\models\BookChapter;
+use Yii;
use yii\data\ActiveDataProvider;
-use yii\helpers\Url;
use yii\web\Controller;
-use Yii;
-class BookController extends Controller
+class AdminController extends Controller
{
public function actions()
diff --git a/frontend/controllers/BookController.php b/common/modules/book/controllers/DefaultController.php
similarity index 87%
rename from frontend/controllers/BookController.php
rename to common/modules/book/controllers/DefaultController.php
index 90b95268..1f78d0e1 100644
--- a/frontend/controllers/BookController.php
+++ b/common/modules/book/controllers/DefaultController.php
@@ -6,17 +6,17 @@
* Time: 下午2:05
*/
-namespace frontend\controllers;
+namespace common\modules\book\controllers;
-use common\models\Book;
-use common\models\BookChapter;
+use common\modules\book\models\Book;
+use common\modules\book\models\BookChapter;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use Yii;
use yii\web\NotFoundHttpException;
-class BookController extends Controller
+class DefaultController extends Controller
{
public function actionIndex()
diff --git a/common/models/Book.php b/common/modules/book/models/Book.php
similarity index 98%
rename from common/models/Book.php
rename to common/modules/book/models/Book.php
index b146389c..f8052218 100644
--- a/common/models/Book.php
+++ b/common/modules/book/models/Book.php
@@ -1,11 +1,11 @@
diff --git a/backend/views/book/_layout.php b/common/modules/book/views/admin/_layout.php
similarity index 97%
rename from backend/views/book/_layout.php
rename to common/modules/book/views/admin/_layout.php
index e048066e..8e6838c8 100644
--- a/backend/views/book/_layout.php
+++ b/common/modules/book/views/admin/_layout.php
@@ -8,10 +8,9 @@
/**
* @var \yii\web\View $this
- * @var common\models\BookChapter $model
+ * @var common\modules\book\models\BookChapter $model
*/
-use yii\helpers\Url;
?>