bug^君 2015-05-20 05:35 采纳率: 25%
浏览 61

渲染部分表格

Is there any way to render partial view which contains a part of form that it's main part is in another view file with AJAX?

I exactly mean one form variable:

`<?php $form = ActiveForm::begin(['enableAjaxValidation' => true,]); ?>`

For Example :

Controller

public function actionOlddetform()
    {
        return $this->renderAjax('_olddet');
    }

View

<?php $form = ActiveForm::begin(['enableAjaxValidation' => true,]); ?>

<?= $form->field($model, 'date')->input() ?>
<?= $form->field($model, 'annotations')->textarea(['rows' => 3]) ?>

<div id="details-form"></div>

<?php ActiveForm::end(); ?>

Part of form included with AJAX for details-form container depends on date value. I know how to check date and show any content of that partial view but when I want to include a part of form I get an error:

PHP Notice 'yii\base\ErrorException' with message 'Undefined variable: form' 
  • 写回答

1条回答 默认 最新

  • weixin_33721427 2015-05-20 05:54
    关注

    It seems you forgot to actually pass the model into your view:

    public function actionOlddetform()
    {
        return $this->renderAjax('_olddet', ['model' => $dataModel]);
    }
    

    And if you want to render "sub-views" from your main view, you need to pass the variables in there as well (even though I don't see a render call in your view):

    <?= $this->render('_formPart', ['form' => $form, 'model' => $model]) ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀