yii2-ledap

the ledap encapsulation for php yii2 framework

Install

The preferred way to install this extension is through composer.

Either run:

composer require --prefer-dist ethercap/yii2-ledap "dev-master"

Or add to the require section of your composer.json file:

"ethercap/yii2-ledap": "dev-master"

Usage

copy layout. you can edit the layout after copy.

cp vendor/ethercap/yii2-ledap/src/gii/layout.php xxx/views/layouts/main.php

Code generator

the use of code generator is similar to gii/crud, let's begin:

php yii gii/ledapCrud --controllerClass="\frontend\controllers\TestController" --modelClass="common\models\Test" --searchModelClass="\frontend\forms\TestSearch"

After run, you can access the page. the page will be follow:

  1. xxController : yii2 Controller to process http request.

  2. views/xx/*.php : the template file, which to rendering html.

  3. views/xx/*.api : the api file, which to rendering api.

  4. xx/web/xx/*.js : the js file of the view。it view be rendering in html with a hash.

the file structure as the following picture.

List View

the javascript has a dataProvider(Note. it's not the php DataProvider) which to control the page.

1.refresh on input

we can add an event on form-item to refresh on inputing. thus, when we input, the table will auto search and refresh.

2. Some DataProvider api

3. grid

grid is a ledap component, which render by columns and dataProvider.

if you're not satisfied with the default content. you can change the grid content by Vue scoped slot. the component will transfer 4 args to scoped slot:

  • model. current model, refer to the row of grid.

  • column. current colomn, refer to the col of grid.

  • index. the index of dp.models. dp.model[index] = model

  • value. the result of the column calculate with the model.

you can also use dataProvider without grid. like dataProvider with "list", or components all by self.

View&Update&Create

type is the switch of the page. it can be set to an item of ["view", "update", "create"].

1.model

the model corresponding to the yii2 Form Model. let's begin:

2.detail

detail is similar to grid. we can use columns to show a detail.the rule is same to the grid.

like grid, we can also use scoped slot to change the default view.

3. form-item

when we want't to show form, the form-item is very import. the form-item contains 4 parts:

  • label

  • hint

  • input

  • error

we cant use like this:

Sometimes, we may want use Other's Vue Component. So I did an example in this package.

I use an vue2-datepickerr to show the code.

we should register the Component in view.js

Other

1.select2 & SearchAction

sometimes we want use a ajax suggestion like select2. the package offer you follows:

  • SearchAction: a php Action to process the request.

after all this config, we have an api "/xx/search" to search data from database.

  • select2 component: vue component to send http request.

2.upload & UploadAction

to be continued.

Tips

  1. be aware of Vue.

  2. do not use yii2 widget.

  3. all component you use should register first. App.register(['xxx'], Vue);

  4. you can use other component.

  5. you can change the request by replace AppAsset.

Last updated

Was this helpful?