yii2
  • yii2-advanced-app
  • 2015-09-03 100 views 0 likes 
    0

    如何將ActiveForm放到gridview列中?以下是我所做的代碼:我試圖渲染頁面,使其包含我需要的活動窗體。把ActiveForm放在Gridview列中Yii2

    'columns' => [ 
         [ 'format' => 'html', 
          'value'=> function($data) { return Html::img($data->imageurl) . " <p class='feedback-username'>" . $data->username . "</p>"; }, 
          'contentOptions'=>['style'=>'width: 30px; height: 30px'], 
         ], 
    
         [ 'format' => 'raw', 
          'value' => function($model) { return "<p class='feedback'>". $model->KOMENTAR ."</p><br><p class='feedback-date'>". $model->TANGGAL ."</p><hr><div id='replay-". $model->ID_KOMENTAR."'><ul></ul></div>";}, 
         ], 
         [ 'format' => 'raw', 
          'contentOptions'=>['style'=>'width: 5px;'], 
          'value' => function($model) { 
           if($model->id == Yii::$app->user->identity->id) { 
            return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',null,['id'=> 'replay-to-'. $model->ID_KOMENTAR ]).' '. 
              Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['update', 'id' => $model->id]).' '. 
              Html::a('<i class="glyphicon glyphicon-trash"></i>', ['delete', 'id' => $model->id], ['data' => ['confirm' => 'Do you really want to delete this element?','method' => 'post']]); 
           } 
           return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',['feedback', 'id' => $model->id],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]); 
          }, 
         ], 
         [ 
    
          'content' => $this->render('feedback_test'), 
         ], 
    

    但我得到這個錯誤:

    PHP Warning – yii\base\ErrorException 
    call_user_func() expects parameter 1 to be a valid callback, function ' 
    <div class="feedback-form"> 
    
    <p>test</p> 
    </div>' not found or invalid function name 
    

    怎樣包括網格視圖的列中的活性形式?

    回答

    2

    試試這個。

    [ 
        'content' => function($model, $key, $index, $column) { 
             echo $this->render('feedback_test'); 
             OR 
             echo $this->render('feedback_test', ['model' => $model]); 
           }, 
    ], 
    
    +0

    確定這就是很好的答案 –

    0

    上面的答案輸出了我的網格上方的窗體。我希望每行數據的列中都有一個表格。我結束了自定義這樣一個ActionColumn:

    [ 
        'class' => 'yii\grid\ActionColumn', 
        'template' => '{map}', 
        'contentOptions' => ['class' => 'text-center'], 
        'buttons' => [ 
        'map' => function ($model) use ($m, $r) { 
         return $this->render('_form', ['model' => $m, 'req' => $model, 'ref' => $r]); 
        }, 
        ], 
        'urlCreator' => function ($action, $model) { 
        if ($action === 'map') { 
         return $model; 
        } 
        }, 
    

    ]

    相關問題