Skip to content

Commit 1eea02b

Browse files
committed
fixes
1 parent f4ec4b6 commit 1eea02b

File tree

10 files changed

+289
-242
lines changed

10 files changed

+289
-242
lines changed

Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Module extends \yii\base\Module
1919

2020
public $imgFileUrl = '/img/blog';
2121

22-
public $adminAccessControl = 'yii\filters\AccessControl';
22+
public $adminAccessControl = null;
2323

2424
public $blogPostPageCount = 10;
2525

README.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Yii2 Super Blog is simple, configured yii2 Module with frontend and backend, clo
2323

2424
> **NOTE:** Module is in initial development. Anything may change at any time.
2525
26-
Installation
27-
------------
26+
## Installation
2827

2928
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
3029

@@ -42,17 +41,25 @@ or add
4241

4342
to the require section of your `composer.json` file.
4443

44+
## Configuration
4545

46+
By default, all images from Imperavi-widget module are uploaded to dir `@frontend/web/img/blog/upload`.
47+
Be sure, this directory is created manually with proper file permissions (chmod).
4648

47-
### Migration
48-
49-
Migration run
49+
Config *common* modules in `common/config/main.php`
5050

5151
```php
52-
yii migrate --migrationPath=@akiraz2/blog/migrations
52+
'modules' => [
53+
'blog' => [
54+
'class' => akiraz2\blog\Module::class,
55+
'urlManager' => 'urlManagerFrontend',// 'urlManager' by default
56+
'imgFilePath' => '@frontend/web/img/blog/',
57+
'imgFileUrl' => '/img/blog/',
58+
],
59+
],
5360
```
5461

55-
### Config url rewrite in /common/config/main.php
62+
Config *url rewrite* in `common/config/main.php` (or separately frontend/backend apps)
5663
```php
5764
'timeZone' => 'Europe/Moscow', //time zone affect the formatter datetime format
5865
'components' => [
@@ -71,32 +78,20 @@ yii migrate --migrationPath=@akiraz2/blog/migrations
7178
],
7279
],
7380
```
74-
### Config common modules in common/config/main.php
75-
76-
```php
77-
'modules' => [
78-
'blog' => [
79-
'class' => akiraz2\blog\Module::class,
80-
'urlManager' => 'urlManagerFrontend',
81-
'imgFilePath' => '@frontend/web/img/blog/',
82-
'imgFileUrl' => '/img/blog/',
83-
//'adminAccessControl' => 'common\components\AdminAccessControl', // 'yii\filters\AccessControl' - by default
84-
],
85-
],
86-
```
8781

88-
### Config backend modules in backend/config/main.php
82+
Config *backend modules* in `backend/config/main.php`
8983

9084
```php
9185
'modules' => [
9286
'blog' => [
9387
'class' => 'akiraz2\blog\Module',
94-
'controllerNamespace' => 'akiraz2\blog\controllers\backend'
88+
'controllerNamespace' => 'akiraz2\blog\controllers\backend',
89+
//'adminAccessControl' => 'common\components\AdminAccessControl', // null - by default
9590
],
9691
],
9792
```
9893

99-
### Config frontend modules in frontend/config/main.php
94+
Config *frontend modules* in `frontend/config/main.php`
10095

10196
```php
10297
//'defaultRoute' => 'blog', //set blog as default route
@@ -121,6 +116,16 @@ yii migrate --migrationPath=@akiraz2/blog/migrations
121116
],
122117
```
123118

119+
120+
### Migration
121+
122+
Migration run after config module
123+
124+
```php
125+
yii migrate --migrationPath=@akiraz2/blog/migrations
126+
```
127+
128+
124129
### Access Url
125130
1. backend : http://backend.you-domain.com/blog
126131
- Category : http://backend.you-domain.com/blog/blog-category
@@ -132,7 +137,7 @@ yii migrate --migrationPath=@akiraz2/blog/migrations
132137

133138
## Usage
134139

135-
### Overriding views
140+
**Overriding views**
136141

137142
When you start using Yii2-blog you will probably find that you need to override the default views provided by the module.
138143
Although view names are not configurable, Yii2 provides a way to override views using themes. To get started you should
@@ -158,7 +163,8 @@ if a view exists in the theme directory it will be used instead of the original
158163
> **NOTE:** Just copy all necessary views from `@akiraz2/yii2-blog/views/frontend/default` to `@app/views/blog` and change!
159164
160165

161-
### How to change upload path Imperavi Redactor widget
166+
167+
**How to change upload path Imperavi Redactor widget**
162168

163169
Yii2 blog module use imperavi redactor 2 Module [https://github.com/yiidoc/yii2-redactor](https://github.com/yiidoc/yii2-redactor) with moduleName "redactorBlog".
164170

@@ -185,11 +191,12 @@ Config backend modules in backend/config/main.php
185191
```
186192

187193

188-
### How to change captcha in Comments
194+
**How to change captcha in Comments**
189195

190196
Not yet... If you are using Recaptcha2 in your project with my yii2-blog, please PR me!
191197

192-
### User model
198+
**User model**
199+
193200
Module Yii2-Blog use `common\models\User`, so if you use custom user component or Module like
194201
[dektrium/yii2-user](https://github.com/dektrium/yii2-user), you should create model under path `common\models\User` with overriding your user-model.
195202

@@ -205,7 +212,7 @@ Module Yii2-Blog use `common\models\User`, so if you use custom user component o
205212
}
206213
```
207214

208-
### CustomAdminAccessControl for backend
215+
**CustomAdminAccessControl for backend**
209216

210217
For example, using [dektrium/yii2-user](https://github.com/dektrium/yii2-user)
211218

@@ -243,7 +250,7 @@ Create file `common\components\AdminAccessControl.php`
243250
}
244251
```
245252

246-
### Opengraph
253+
**Opengraph**
247254

248255
Please, add component [dragonjet/yii2-opengraph](https://packagist.org/packages/dragonjet/yii2-opengraph) to your project.
249256
```
@@ -260,6 +267,13 @@ Configuration `common/config/main.php` or `frontend/config/main.php`
260267
//....
261268
],
262269
```
270+
271+
## TODO
272+
273+
* refactoring code (specially BlogCategory)
274+
* create widgets
275+
* translate to languages
276+
* change default design and styles for frontend blog
263277

264278

265279
## Support

controllers/backend/BaseAdminController.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ public function behaviors() {
2929
'actions' => [
3030
'delete' => ['POST'],
3131
],
32-
],
33-
'access' => [
34-
'class' => $this->module->adminAccessControl,
35-
],
32+
]
3633
];
3734
}
35+
36+
public function init()
37+
{
38+
if($this->module->adminAccessControl) {
39+
$this->attachBehavior('access', [
40+
'class' => $this->module->adminAccessControl,
41+
]);
42+
}
43+
44+
parent::init();
45+
}
3846
}

controllers/backend/BlogCategoryController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function actionCreate()
7171
{
7272
$model = new BlogCategory();
7373

74-
if (isset($_GET['parent_id']) && $_GET['parent_id'] > 0) {
75-
$model->parent_id = $_GET['parent_id'];
74+
if (Yii::$app->request->get('parent_id')>0) {
75+
$model->parent_id = Yii::$app->request->get('parent_id');
7676
}
7777

7878
if ($model->load(Yii::$app->request->post()) && $model->save()) {

controllers/backend/BlogPostController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function actionCreate()
9393
* If update is successful, the browser will be redirected to the 'view' page.
9494
* @param integer $id
9595
* @return mixed
96+
* @throws NotFoundHttpException
9697
*/
9798
public function actionUpdate($id)
9899
{
@@ -112,6 +113,7 @@ public function actionUpdate($id)
112113
* If deletion is successful, the browser will be redirected to the 'index' page.
113114
* @param integer $id
114115
* @return mixed
116+
* @throws NotFoundHttpException
115117
*/
116118
public function actionDelete($id)
117119
{

controllers/backend/BlogTagController.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use yii\web\NotFoundHttpException;
1414

1515
/**
16-
* TagController implements the CRUD actions for Tag model.
16+
* BlogTagController implements the CRUD actions for BlogTag model.
1717
*/
1818
class BlogTagController extends BaseAdminController
1919
{
@@ -53,7 +53,7 @@ public function actionView($id)
5353
* Finds the Tag model based on its primary key value.
5454
* If the model is not found, a 404 HTTP exception will be thrown.
5555
* @param string $id
56-
* @return Tag the loaded model
56+
* @return BlogTag the loaded model
5757
* @throws NotFoundHttpException if the model cannot be found
5858
*/
5959
protected function findModel($id)
@@ -66,7 +66,7 @@ protected function findModel($id)
6666
}
6767

6868
/**
69-
* Creates a new Tag model.
69+
* Creates a new BlogTag model.
7070
* If creation is successful, the browser will be redirected to the 'view' page.
7171
* @return mixed
7272
*/
@@ -86,7 +86,7 @@ public function actionCreate()
8686
}
8787

8888
/**
89-
* Updates an existing Tag model.
89+
* Updates an existing BlogTag model.
9090
* If update is successful, the browser will be redirected to the 'view' page.
9191
* @param string $id
9292
* @return mixed
@@ -108,11 +108,14 @@ public function actionUpdate($id)
108108
}
109109

110110
/**
111-
* Deletes an existing Tag model.
111+
* Deletes an existing BlogTag model.
112112
* If deletion is successful, the browser will be redirected to the 'index' page.
113113
* @param string $id
114114
* @return mixed
115115
* @throws NotFoundHttpException
116+
* @throws \Exception
117+
* @throws \Throwable
118+
* @throws \yii\db\StaleObjectException
116119
*/
117120
public function actionDelete($id)
118121
{

controllers/backend/UploadController.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@ class UploadController extends BaseAdminController
1212

1313
public function init()
1414
{
15+
parent::init();
1516
$this->module = \Yii::$app->getModule(\Yii::$app->getModule('blog')->redactorModule);
16-
parent::init(); // TODO: Change the autogenerated stub
17-
}
18-
19-
public function behaviors()
20-
{
21-
return [
22-
[
23-
'class' => 'yii\filters\ContentNegotiator',
24-
'formats' => [
25-
'application/json' => Response::FORMAT_JSON
26-
],
27-
]
28-
];
17+
$this->attachBehavior('content' , [
18+
'class' => 'yii\filters\ContentNegotiator',
19+
'formats' => [
20+
'application/json' => Response::FORMAT_JSON
21+
],
22+
]);
2923
}
3024

3125
public function actions()

0 commit comments

Comments
 (0)