bootstrap-widgets.md 2.58 KB
Newer Older
Qiang Xue committed
1
Bootstrap Widgets
2
=================
3

Qiang Xue committed
4 5
> Note: This chapter is under development.

Larry Ullman committed
6
Out of the box, Yii includes support for the [Bootstrap 3](http://getbootstrap.com/) markup and components framework (also known as "Twitter Bootstrap"). Bootstrap is an excellent, responsive framework that can greatly speed up the client-side of your development process.
7

Larry Ullman committed
8
The core of Bootstrap is represented by two parts:
9

Larry Ullman committed
10
- CSS basics, such as a grid layout system, typography, helper classes, and responsive utilities.
11
- Ready to use components, such as forms, menus, pagination, modal boxes, tabs etc.
12 13 14 15

Basics
------

Larry Ullman committed
16
Yii doesn't wrap the bootstrap basics into PHP code since HTML is very simple by itself in this case. You can find details
17 18 19 20 21
about using the basics at [bootstrap documentation website](http://getbootstrap.com/css/). Still Yii provides a
convenient way to include bootstrap assets in your pages with a single line added to `AppAsset.php` located in your
`config` directory:

```php
Alexander Makarov committed
22
public $depends = [
23 24 25
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset', // this line
    // 'yii\bootstrap\BootstrapThemeAsset' // uncomment to apply bootstrap 2 style to bootstrap 3
Alexander Makarov committed
26
];
27 28
```

29
Using bootstrap through Yii asset manager allows you to minimize its resources and combine with your own resources when
30 31 32 33 34 35
needed.

Yii widgets
-----------

Most complex bootstrap components are wrapped into Yii widgets to allow more robust syntax and integrate with
36 37
framework features. All widgets belong to `\yii\bootstrap` namespace:

38
- [[yii\bootstrap\ActiveForm|ActiveForm]]
39 40 41 42 43 44 45 46 47 48 49 50
- [[yii\bootstrap\Alert|Alert]]
- [[yii\bootstrap\Button|Button]]
- [[yii\bootstrap\ButtonDropdown|ButtonDropdown]]
- [[yii\bootstrap\ButtonGroup|ButtonGroup]]
- [[yii\bootstrap\Carousel|Carousel]]
- [[yii\bootstrap\Collapse|Collapse]]
- [[yii\bootstrap\Dropdown|Dropdown]]
- [[yii\bootstrap\Modal|Modal]]
- [[yii\bootstrap\Nav|Nav]]
- [[yii\bootstrap\NavBar|NavBar]]
- [[yii\bootstrap\Progress|Progress]]
- [[yii\bootstrap\Tabs|Tabs]]
51 52 53 54 55 56 57


Using the .less files of Bootstrap directly
-------------------------------------------

If you want to include the [Bootstrap css directly in your less files](http://getbootstrap.com/getting-started/#customizing)
you may need to disable the original bootstrap css files to be loaded.
58
You can do this by setting the css property of the [[yii\bootstrap\BootstrapAsset|BootstrapAsset]] to be empty.
it3rmit committed
59
For this you need to configure the `assetManager` application component as follows:
60 61 62 63 64 65 66 67 68 69

```php
    'assetManager' => [
        'bundles' => [
            'yii\bootstrap\BootstrapAsset' => [
                'css' => [],
            ]
        ]
    ]
```