如何在yii2中加载远程模态内容

时间:2015-02-16 17:35:28

标签: php jquery twitter-bootstrap web yii2

我一直在尝试在相同的yii2视图

上为不同的bootstrap模式加载远程内容
<?php
    $label  = $model->getAttributeLabel('educationId');
    $addon = [
        'prepend' => [
            'content' => Html::icon('book')
        ],
        'append' => [
            'content' => Html::button(
                Html::icon('plus'), [
                    'class' => 'btn btn-success',
                    'title' => 'Add New' . $label,
                    'onclick' => new JsExpression('showModal();'),
                ]
            ),
            'asButton' => true
        ]
    ];
    echo  Html::tag('label',$model->getAttributeLabel('educationId'), ['class'=>'control-label']);
    echo Select2::widget([
        'model' => $model,
        'attribute' => 'educationId',
        'data' => ArrayHelper::map ( EducationLevel::find ()->all (), 'id', 'name' ),
        'options' => ['placeholder' => 'Select Education Level ...','template' => 'label}\n{error}'],
        'addon' => $addon,
        'pluginOptions' => [
            'maximumInputLength' => 10
        ],
    ]);

JS功能

Function showModal(){
    $('#addEducationModal').modal({
        remote: 'modal.html',
        show: true
    });
}

因此用户将点击文本字段的插件按钮,模式将显示,其他文本字段应具有相同的机制和不同的模态内容。

然而,我得到的只是褪色的背景。

1 个答案:

答案 0 :(得分:0)

我能够让它发挥作用而不仅仅是。

我的问题主要是因为yii cashes生成文件以便解决我删除生成的文件并确保内容生成新鲜:)

我没有使用JQuery加载函数。

见下面的代码:

PHP查看代码

        $label  = $model->getAttributeLabel('majorId');
        $addon = [
        'prepend' => [
        'content' => Html::icon('book')
        ],
        'append' => [
        'content' => Html::button(Html::icon('plus'), [
                'class' => 'btn btn-success',
                'title' => 'Add New' . $label ,
                'data-toggle' => 'modal',
                'data-target' => '#addModal',
                'href'=> 'addMajorModal.html',
                ]),
                'asButton' => true
                ]
                ];
        echo  Html::tag('label',$model->getAttributeLabel('majorId'),['class'=>'control-label']);
        echo Select2::widget([
                'model' => $model,
                'attribute' => 'majorId',
                'data' =>ArrayHelper::map ( Major::find ()->all (), 'id', 'name' ),
                'options' => ['placeholder' => 'Select Major ...','template' => 'label}\n{error}'],
                'addon' => $addon,
                'pluginOptions' => [
                'maximumInputLength' => 10
                ],
                ]);

<div class="modal fade" id="addModal" >
  <div class="modal-dialog" dir="rtl">
    <div class="modal-content" dir="rtl">
                <!-- Content will be loaded here from "addMajorModal.html" file -->
            </div>
        </div>
    </div>

模态文件内容

 <div class="modal-header panel-primary" dir="rtl" horizantal-aligned="">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">إضا�ة جديد</h4>
      </div>
      <div class="modal-body" dir="rtl">
        <div id="login-boxs" class="login-popup>
           <form id="newCat" method="post" class="signin" dir="rtl" action="#">
               <div class="form-group">
                    <label for="certName" class="control-label">مسمى التخصص </label>
                    <input type="text" name="name" data-val="true" data-val-required="ErrMsg" data-rule-required="true" placeholder="مسمى الشهادة" class="form-control" id="certName">
               </div>
                <div class="form-group">
                    <label for="certShortDesc" class="control-label">وص� قصير </label>
                    <input type="text" name="shdesc"  data-rule-required="true" placeholder="وص� قصير" class="form-control" id="certShortDesc" required>
               </div>
          </form>
                            </div>
      </div>
      <div class="modal-footer" dir="rtl">
      <div class="col-lg-6" dir="rtl">
        <div class="progress" >
                       <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 100%;" id="progresBarUpload">       
                       </div>
                   </div>
      </div>
      <div class="col-lg-6" dir="rtl">
      <button type="button" class="btn btn-danger" dir="rtl" data-dismiss="modal"><i class="glyphicon glyphicon-remove"> </i>Close</button>
        <button id="submitButton" type="button" dir="rtl" class="btn btn-primary" onclick="createCertificate()"><i class="glyphicon glyphicon-ok"> </i>Save changes</button>

      </div>

              </div>

多数民众赞成,这个模式将根据yii追加生成HTML

加载

据我所知,这将在Bootstrap 3.3之前可行,因为版本4中将弃用远程内容