Skip to content

Commit 4a496bc

Browse files
authored
Create backend-bootstrap4.md
1 parent 83ffa3d commit 4a496bc

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

docs/backend-bootstrap4.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Generating a Backend with boostap4
2+
==================================
3+
4+
Steps:
5+
6+
- Generate some CRUDs for the backend:
7+
8+
./yii gii/crud --interactive=0 --modelClass='common\models\User' --searchModelClass='backend\models\UserSearch' --controllerClass='backend\controllers\UserController' --enableI18N --viewPath=@backend/views/user
9+
./yii gii/crud --interactive=0 --modelClass='common\models\Task' --searchModelClass='backend\models\TaskSearch' --controllerClass='backend\controllers\TaskController' --enableI18N --viewPath=@backend/views/task
10+
# ... adjust the above commands based on your models
11+
12+
- `composer require yiisoft/yii2-bootstrap4`
13+
- Create `backend/assets/AppAsset.php`:
14+
15+
```php
16+
<?php
17+
18+
namespace backend\assets;
19+
20+
use yii\bootstrap4\BootstrapAsset;
21+
use yii\web\AssetBundle;
22+
use yii\web\YiiAsset;
23+
24+
class AppAsset extends AssetBundle
25+
{
26+
public $depends = [
27+
YiiAsset::class,
28+
BootstrapAsset::class,
29+
];
30+
}
31+
```
32+
- require Asset in main layout (`backend/views/layouts/main.php`):
33+
34+
```diff
35+
diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php
36+
index 2180ce6..0f18ba2 100644
37+
--- a/backend/views/layouts/main.php
38+
+++ b/backend/views/layouts/main.php
39+
@@ -5,6 +5,8 @@ use yii\helpers\Html;
40+
/** @var $this \yii\web\View */
41+
/** @var $content string */
42+
43+
+\backend\assets\AppAsset::register($this);
44+
+
45+
?>
46+
<?php $this->beginPage() ?>
47+
<!DOCTYPE html>
48+
```
49+
50+
- Add a navigation to the mail layout:
51+
52+
```php
53+
<?php \yii\bootstrap4\NavBar::begin() ?>
54+
55+
<?= \yii\bootstrap4\Nav::widget([
56+
'items' => [
57+
[
58+
'label' => 'Tasks',
59+
'url' => ['/task/index'],
60+
],
61+
[
62+
'label' => 'Users',
63+
'url' => ['/user/index'],
64+
],
65+
]
66+
]) ?>
67+
68+
<?php \yii\bootstrap4\NavBar::end() ?>
69+
```
70+
71+
72+

0 commit comments

Comments
 (0)