如何将输入文本放入yii2 kartik gridview并将params从视图传递给控制器​​?

时间:2017-02-23 16:05:58

标签: php gridview yii2

我已尝试使用此代码,但看起来没有问题,没有参加GET的parm。

这个想法是为数量输入一个输入框(属性cantidad),然后在用户按下视图按钮时传递此数量(它是我自定义的视图功能)

查看代码:

<?php

Html::beginForm(Url::toRoute(["customers/addproduct", 'id'=>$searchModel->id]), "POST");

$dataProvider->pagination = [
    'pagesize' => 10,
];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'summary' => "Mostrando {begin} - {end} de {totalCount} productos",
    'containerOptions' => ['style' => 'overflow: auto'],
    'headerRowOptions' => ['class' => 'kartik-sheet-style'],
    'filterRowOptions' => ['class' => 'kartik-sheet-style'],
    'pjax' => false,
    'columns' => [
        ['class'=>'kartik\grid\SerialColumn'],
        [
            'label' => 'Imagen',
            'attribute' => 'id_image',
            'vAlign' => 'middle',
            'format' => 'image',
            'value' => function($searchModel) {
                return 'http://prestashop.xxxxxx.xxx:1100/'.$searchModel->id_image.'-home/'.$searchModel->link_rewrite.'.jpg';
            },
        ],
        [
            'label' => 'EAN',
            'attribute'=>'ean13',
            'vAlign'=>'left',
            'pageSummary'=>'Total',
        ],
        [
            'attribute'=>'producto',
            'vAlign'=>'left',
            'pageSummary'=>'Total',
        ],
        'categoria',
        'atributos',
        [
            'header' => 'Cantidad',
            'attribute'=>'cantidad',
            'vAlign'=>'middle',
            'hAlign'=>'right',
            'value' => function($searchModel){
                return Html::textInput('quantity'.$searchModel->id, $searchModel->cantidad, ['value'=>'quantity', 'maxlength'=>10,'style'=>'width:80px']);
            },
            'format' => 'raw',
        ],
        [
            'label' => 'Precio',
            'attribute' => 'precio',
            'vAlign' => 'middle',
            'hAlign' => 'right',
            'format' => ['decimal', 2],
        ],
        [
            'class' => 'kartik\grid\ActionColumn',
            'template' => '{view}',
            'dropdown' => false,
            'vAlign' => 'middle',
            'buttons' => [
                'view' => function ($url, $model) {
                    return Html::a('Añadir Producto', $url, [
                        'title' => Yii::t('app', 'Añadir'),
                        'type' => 'submit',
                    ]);
                }
            ],
            'urlCreator' => function ($action, $model, $key, $index) {
                if ($action === 'view') {
                    $url = 'index.php?r=customers/shopping&act=v&id='.$model->id.'&c='.$model->id_customer;
                    return $url;
                }
            }
        ],
    ],
    // set export properties
    'export' => [
        'fontAwesome' => true,
    ],
    'bordered' => false,
    'striped' => false,
    'condensed' => true,
    'responsive' => true,
    'hover' => true,
    'showPageSummary' => true,
    'showFooter' => false,
    'floatHeader' => true,
    'floatHeaderOptions' => ['scrollingTop' => '50'],
    'pjax' => false,
    'panel' => [
        'type' => GridView::TYPE_SUCCESS,
        'heading' => '<i class="glyphicon glyphicon-align-justify"></i> Productos',
        'footer' => '',
        'after' => false,
    ],
    'persistResize' => false,
]);

Html::endForm()

控制器代码

if (Yii::$app->request->get())
{
    if (isset($_GET['c']))
    {
        $id_unique = Html::encode($_GET["id"]);
        $quantity = Html::encode($_POST['quantity'.$id_unique]);
        $id_customer = Html::encode($_GET["c"]);
        ($quantity > 0) ? $d = 1 : $d = 2;
        $this->addProduct($idshop, $id_customer);
    }
    elseif (isset($_GET['shoppingcart']))
    {
        $id_supplier = Html::encode($_GET["shoppingcart"]);
        //return Yii::$app->response->redirect(Url::to(["shoppings/vieworder"]));
    }
    elseif (isset($_GET['bootbox']))
    {
        $id_supplier = Html::encode($_GET["checkout"]);
        //$this->launchModalDialog();
    }
    else
    {
        $id_supplier = $user->id_supplier;
    }
}
else
{
    $searchModel = new TablaNsCustomerProductSearch;
    $dataProvider = $searchModel->searchCustomer(Yii::$app->request->queryParams);

    return $this->render('shopping/shopping', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);                   
}

$searchModel = new TablaNsCustomerProductSearch;
$dataProvider = $searchModel->searchCustomer(Yii::$app->request->queryParams);

return $this->render('shopping/shopping', [
    'searchModel' => $searchModel,
    'dataProvider' => $dataProvider,
]);

谢谢!

0 个答案:

没有答案