evgeniydev/yii2-form-creator-behavior
Composer 安装命令:
composer require evgeniydev/yii2-form-creator-behavior
包简介
Yii2 behavior to create view form
README 文档
README
This is behavior which generate view form for methods CREATE and UPDATE.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require evgeniydev/yii2-form-creator-behavior
or add
"evgeniydev/yii2-form-creator-behavior": "*"
to the require section of your composer.json file.
Basic usage
Model file (app/models/SomeModel.php)
... use evgeniydev\yii2\behaviors\FormCreatorBehavior ... class SomeModel extends \yii\base\Model { public $field1; public $field2; public $field3; ... public function behaviors() { return [ ... 'formBehavior' => [ 'class' => FormCreatorBehavior::className(), 'attributes' => [ 'field1' => [ // <input type="text"> 'type' => FormCreatorBehavior::TEXT_INPUT_TYPE, 'inputOptions' => [ 'class' => 'someClass', // other html options ], ], 'field2', // by default generate <input type="text"> 'field3' => [ // generate <select>...</select> 'type' => FormCreatorBehavior::DROPDOWNLIST_TYPE, 'items' => ['option1', 'option2'], 'inputOptions' => [ 'prompt' => 'Choose option', ], ], 'field4' => function($form, $model) { // callable function to return view field for this form return $form->field($model) } // other fields ], ] ... ]; }
Controller file (app/controllers/SomeController.php)
use app\models\SomeModel.php ... public function actionCreate() { $model = new SomeModel(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { // model save } return $this->render('form', [ 'model' => $model, ]); } public function actionUpdate($id) { $model = SomeModel::findOne($id); if (!$model) { // throw not found } if ($model->load(\Yii::$app->request->post()) && $model->save()) { // model update } return $this->render('form', [ 'model' => $model, ]); } ...
View file (app/views/some/form.php)
<?= $model->form; ?>
Other field types
Checkbox
'field1' => [ 'type' => FormCreatorBehavior::CHECKBOX_TYPE, 'inputOptions' => [ 'class' => 'someClass', // other html options ], ],
Checkbox list
'field1' => [ 'type' => FormCreatorBehavior::CHECKBOXLIST_TYPE, 'items' => ['check1', 'check2'], 'inputOptions' => [ 'class' => 'someClass', // other html options ], ],
Widget
'field1' => [ 'type' => FormCreatorBehavior::WIDGET_TYPE, 'widgetClass' => '' // widget class name 'widgetOptions' => [...], // widget options ],
List box
'field1' => [ 'type' => FormCreatorBehavior::LISTBOX_TYPE, 'items' => ['check1', 'check2'], 'inputOptions' => [ 'class' => 'someClass', // other html options ], ],
Input with custom type
'field1' => [ // <input type="tel"> 'type' => FormCreatorBehavior::INPUT_TYPE, 'inputType' => 'tel', 'inputOptions' => [ 'class' => 'someClass', // other html options ], ],
Full list constants types
- TEXT_INPUT_TYPE - text input
- TEXTAREA_TYPE - textarea
- CHECKBOX_TYPE - checkbox
- DROPDOWNLIST_TYPE - dropdownlist
- WIDGET_TYPE - widget
- INPUT_TYPE - input with custom type
- HIDDEN_INPUT_TYPE - hidden input
- FILE_INPUT_TYPE - file input
- PASSWORD_INPUT_TYPE - password input
- RADIO_TYPE - radio input
- RADIOLIST_TYPE - radio list
- CHECKBOXLIST_TYPE - checkboxe list
- LISTBOX_TYPE - list box
Other configuration
Input with callable function function template: function($form, $model){ return ...; }
'field1' => function($form, $model) { // callable function return $form->field($model, 'field1'); },
Label
'field1' => [ 'type' => FormCreatorBehavior::TEXT_INPUT_TYPE, 'label' => 'Some label', // or false, if want not show label ... ],
Hint (short form)
'field1' => [ 'type' => FormCreatorBehavior::TEXT_INPUT_TYPE, 'hint' => 'Some hint', ... ],
or full form
'field1' => [ 'type' => FormCreatorBehavior::TEXT_INPUT_TYPE, 'hint' => [ 'content' => 'Some content', // hint content 'options' => [...], // hint options ], ... ],
Form configuration
'class' => FormCreatorBehavior::className(), 'attributes' => [...], // array attributes 'formOptions' => [ 'options' => [ 'enctype' => 'multipart/form-data' ], 'id' => 'Some id', ... // other \yii\widgets\ActiveForm widget options ]
Template view
'class' => FormCreatorBehavior::className(), 'attributes' => [...], // array attributes 'template' => '{items}{beginBlockButtons}{submitButton}{cancelButton}{endBlockButtons}', // template view
{items} - elements of form
{beginBlockButtons} - open tag for block with form buttons
{submitButton} - submit form button
{cancelButton} - cancel form button
{endBlockButtons} - end tag for block with buttons
Submit button options
'class' => FormCreatorBehavior::className(), 'attributes' => [...], // array attributes 'submitButtonOptions' => [ 'createButtonOptions' => [ // create button options 'title' => 'Create', // text create button 'tag' => 'input', // tag create button (input|button) 'htmlOptions' => [...], // create button html options ], 'updateButtonOptions' => [ 'title' => 'Update', // text update button 'tag' => 'input', // tag update button (input|button) 'htmlOptions' => [...], // update button html options ], ],
Cancel button options
'class' => FormCreatorBehavior::className(), 'attributes' => [...], // array attributes 'cancelButtonOptions' => [ 'show' => true, // true or false, show cancel button 'title' => 'Cancel', // text cancel button 'action' => ['index'], // url to go cancel operation, by default is action index 'htmlOptions' => [...], // cancel button html options ],
Wrapper block buttons form options
'class' => FormCreatorBehavior::className(), 'attributes' => [...], // array attributes 'wrapperBlockButtonsOptions' => [ 'tag' => 'div', // tag name wrapper buttons block or false 'htmlOptions' => [...], // cancel button html options ],
Tabs
'class' => FormCreatorBehavior::className(), 'tabOptions' => [ // tab options 'widgetName' => '...', // tab widget name, default is \yii\bootstrap\Tabs 'widgetOptions' => [ 'keyNameContentField' => '...', // key name tab content field, default 'content' // ... other some widget options ], 'tabs' => [ [ // tab 1 'tabAttributes' => ['someField1', 'someField2', ...], // list attributes on this tab, 'content' => '{items}', // template of content tab, {items} to be replaced by fields attribues on this tab, 'content' if // keyNameContentField = 'content', if keyNameContentField not equal 'content', then key 'content' key must be other // .. other tab options for this widget tab, example \yii\bootstrap\Tabs: 'title' => 'Some title', ], [ // tab 2 'tabAttributes' => ['someField3', 'someField4', ...], // list attributes on this tab, // .. other tab options for this widget tab, example \yii\bootstrap\Tabs: 'title' => 'Some title', ], // ... other tabs ], ],
evgeniydev/yii2-form-creator-behavior 适用场景与选型建议
evgeniydev/yii2-form-creator-behavior 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Behavior」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evgeniydev/yii2-form-creator-behavior 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evgeniydev/yii2-form-creator-behavior 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evgeniydev/yii2-form-creator-behavior 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A CakePHP plugin to provide easy access to zumba/swivel
A custom URL rule class for Yii 2 which allows to create translated URL rules
This is a set of Yii2 behaviors extensions
Model behaviors for the li₃ PHP framework
A CakePHP behavior to validate foreign keys
Yii2-article is a module offering basic CMS-functionality
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-11-16