承接 inspire-agency/yii2-ajax-new 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inspire-agency/yii2-ajax-new

Composer 安装命令:

composer require inspire-agency/yii2-ajax-new

包简介

This widget allows you to easily create a new related entity from within a form in Yii, in a bootstrap Modal view.

README 文档

README

This widget allow you to easily create a new related entity instance from within a form in Yii, in a bootstrap Modal view.

Let's suppose for instance that you have an Article model with a manyToOne relation with a Category model (article.category_id = category.id)

When creating a new Article, you realize that you didn't create the target Category yet. You would normally cancel the Article creation, create the Category, and then go back to the Article creation.

yii2-ajax-new will allow you to avoid that hassle by creating the new Category right away from the Article form.

A complete sample if provided below.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require inspire-agency/yii2-ajax-new "*"

or add

"inspire-agency/yii2-ajax-new": "*"

to the require section of your composer.json file.

Configuration

Assuming you have created both Article and Category models with the relation Article.category_id = Category.id, you will need to:

  1. Configure your CategoryController as follows:
    public function actions()
    {
        return [
            'ajaxNew' => [
                'class'      => '\inspire\action\AjaxNewAction',
                'viewFile'   => '_form',
                'model'      => new Category(),
                'attr_id'    => 'id',
                'attr_label' => 'label',
            ]
        ];
    }
  1. Add the AjaxNew widget in your article/_form view:
$newCategory = AjaxNew::widget([
    'url' => Url::toRoute(['/category/ajaxNew']),
    'header' => '<strong>' . Yii::t('app', 'Create new category') . '</strong>',
    'selector' => '#article-category',
]);

// ...

<?= $form->field($model, 'category', [
'template' => "{label} " . $newCategory . " \n{input}\n{hint}\n{error}",

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 5
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-11