Skip to content

Commit 874235f

Browse files
committed
add Page CRUD
1 parent b315b7d commit 874235f

25 files changed

+672
-75
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,74 @@ or add
2020
```
2121

2222
to the require section of your `composer.json` file.
23+
24+
Then You have run console command for install this module:
25+
26+
```
27+
php yii module/install product
28+
```
29+
30+
and module will be added to your application config (`@app/config/installed_modules.php`)
31+
32+
Concept
33+
-------
34+
35+
This module allows you to build dynamic pages which consist of blocks (widget with config).
36+
You can create own type of widgets and register it in BlockManager.
37+
38+
39+
BlockManager
40+
------------
41+
42+
This component contains information about available blocks.
43+
You can override it:
44+
45+
```php
46+
'cms' => [
47+
'class' => 'nullref\\cms\\Module',
48+
'blockManagerClass' => 'app\components\BlockManager',
49+
],
50+
```
51+
52+
and add in your class own blocks:
53+
54+
```php
55+
class BlockManager extends BaseBlockManager
56+
{
57+
public function getList()
58+
{
59+
return array_merge([
60+
'smile' => 'app\blocks\smile', //namespace of block files
61+
], parent::getList());
62+
}
63+
}
64+
```
65+
66+
Also you can register your block in runtime:
67+
68+
```php
69+
Block::getManager()->register('smile','app\blocks\smile');
70+
//or
71+
\Yii::$app->getModule($moduleId)->get('blockManager')->register('smile','app\blocks\smile');
72+
```
73+
74+
75+
76+
Block structure convention
77+
--------------------------
78+
79+
Each valid block it's folder with to classes:
80+
81+
- Block - define data block to use
82+
- Widget - run with data when this block use on page
83+
84+
In most cases where is form file in this folder.
85+
86+
When you add own block you have to set unique id and namespace of block files folder.
87+
88+
89+
90+
Using with yii2-admin module
91+
----------------------------
92+
93+
You can use this module with [Yii2 Admin](https://github.com/NullRefExcep/yii2-admin) module.

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
],
99
"require": {
1010
"yiisoft/yii2": "*",
11+
"yiisoft/yii2-jui": "~2.0.0",
12+
"mihaildev/yii2-ckeditor": "*",
1113
"nullref/yii2-useful": "dev-master",
1214
"nullref/yii2-core": "dev-master",
1315
"nullref/yii2-admin": "dev-master"

src/Bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
namespace nullref\cms;
44

55

6+
use yii\base\ActionEvent;
67
use yii\base\Application;
78
use yii\base\BootstrapInterface;
9+
use yii\base\Controller;
10+
use yii\base\Event;
11+
use yii\web\ErrorAction;
812

913
class Bootstrap implements BootstrapInterface
1014
{
1115
public function bootstrap($app)
1216
{
1317
$prefix = $app->getModule('cms')->urlPrefix;
1418
$app->urlManager->addRules([
15-
$prefix.'/<route:[a-zA-Z0-9-/]+>' => '/cms/page/index'
19+
$prefix.'/<route:[a-zA-Z0-9-/]+>' => '/cms/page/view'
1620
]);
1721
}
1822

src/Module.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ public static function getAdminMenu()
3030
{
3131
return [
3232
'label' => Yii::t('cms', 'CMS'),
33-
'icon' => 'archive',
33+
'icon' => 'columns',
3434
'items'=>[
3535
[
3636
'label' => Yii::t('cms', 'Pages'),
37-
'icon' => 'archive',
37+
'icon' => 'copy',
3838
'url' => '/cms/admin/page',
3939
],
4040
[
4141
'label' => Yii::t('cms', 'Blocks'),
42-
'icon' => 'archive',
42+
'icon' => 'clone',
4343
'url' => '/cms/admin/block',
4444
],
4545
]

src/blocks/html/Block.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
*/
99
class Block extends BaseBlock
1010
{
11-
public $content;
11+
public $content;
12+
public $tag = 'div';
13+
public $tagClass = 'alert alert-success';
1214

1315
public function getName()
1416
{
@@ -18,16 +20,8 @@ public function getName()
1820
public function rules()
1921
{
2022
return [
21-
[['content'],'required'],
23+
[['content','tag','tagClass'],'required'],
2224
];
2325
}
2426

25-
public function getConfig()
26-
{
27-
return [
28-
'content'=>$this->content,
29-
];
30-
}
31-
32-
3327
}

src/blocks/html/Widget.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55

66
namespace nullref\cms\blocks\html;
77

8-
use nullref\cms\components\Widget as BaseWidget;
8+
use nullref\cms\blocks\text\Widget as BaseWidget;
99
use yii\helpers\Html;
1010

1111

1212
class Widget extends BaseWidget
1313
{
14-
public $content;
15-
1614
public function run()
1715
{
18-
return Html::encode($this->content);
16+
return
17+
Html::beginTag($this->tag,['class'=>$this->tagClass]).
18+
Html::encode($this->content).
19+
Html::endTag($this->tag);
1920
}
2021
}

src/blocks/html/_form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
* @var $block \nullref\cms\blocks\html\Block
55
*/
66

7-
echo $form->field($block, 'content')->textarea();
7+
echo $form->field($block, 'content')->textarea();
8+
echo $form->field($block, 'tag')->textInput();
9+
echo $form->field($block, 'tagClass')->textInput();

src/blocks/text/Block.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
*/
99
class Block extends BaseBlock
1010
{
11-
public $content;
11+
public $content;
12+
public $tag = 'div';
13+
public $tagClass = 'alert alert-success';
1214

1315
public function getName()
1416
{
@@ -18,15 +20,7 @@ public function getName()
1820
public function rules()
1921
{
2022
return [
21-
[['content'],'required'],
22-
];
23-
}
24-
25-
26-
public function getConfig()
27-
{
28-
return [
29-
'content'=>$this->content,
23+
[['content','tag','tagClass'],'required'],
3024
];
3125
}
3226
}

src/blocks/text/Widget.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
class Widget extends BaseWidget
1313
{
14-
public $content;
14+
public $content;
15+
public $tag = 'div';
16+
public $tagClass = 'alert alert-success';
17+
1518

1619
public function run()
1720
{
18-
return Html::encode($this->content);
21+
return Html::tag($this->tag, $this->content,['class'=>$this->tagClass]);
1922
}
2023
}

src/blocks/text/_form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
* @var $block \nullref\cms\blocks\text\Block
55
*/
66

7-
echo $form->field($block, 'content')->textarea();
7+
echo $form->field($block, 'content')->textarea();
8+
echo $form->field($block, 'tag')->textInput();
9+
echo $form->field($block, 'tagClass')->textInput();

0 commit comments

Comments
 (0)