Hi.
I’m new to Yii, and I would like to get the selected rows from my gridview to be part of form data so i can submit all the information together.
my view is like this:
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'uc-form',
'enableAjaxValidation' => true,
));
?>
...
<?php
$gridDataProvider = new CArrayDataProvider(Docente::model()->findAllAttributes(null, true),array(
'keyField' => 'idDoce', // PRIMARY KEY attribute of $list member objects
'id' => 'docentes' // ID of the data provider itself
));
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'docentes-grid',
'type'=>'striped bordered condensed',
'dataProvider'=>$gridDataProvider,
'template'=>"{items}",
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'selectableRows'=>2,
'id'=>'checkbox'
),
array('name'=>'nome', 'header'=>'Nome'),
array('name'=>'email', 'header'=>'Email'),
),
));
?>
<?php
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Criar' : 'Save',
));
$this->endWidget();
?>
So when i click submit i want to send the form data, and the value that i get from execute
$.fn.yiiGridView.getChecked('docentes-grid','checkbox')
How can I do that?
in the controller is like this:
public function actionCreate() {
$model = new Uc;
$this->performAjaxValidation($model, 'uc-form');
if (isset($_POST['Uc'])) {
$model->setAttributes($_POST['Uc']);
$relatedData = array(
'alunos' => $_POST['Uc']['alunos'] === '' ? null : $_POST['Uc']['alunos'],
'docentes' => $_POST['Uc']['docentes'] === '' ? null : $_POST['Uc']['docentes'],
);
if ($model->saveWithRelated($relatedData)) {
if (Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
else
$this->redirect(array('view', 'id' => $model->idDisc));
}
}
$this->render('create', array( 'model' => $model));
}