Greetings,
I am very new to the Yii framework and to this forum so forgive me for asking a possibly silly question.
I have an index file with JavaScript that sends data to my ParcelController like so.
function editSelected(){
var editIds = $('#w0').yiiGridView('getSelectedRows');
var windowEnd = document.getElementById("window_end_dt").value;
var windowStart = document.getElementById("window_start_dt").value;
var note = document.getElementById("note_txt").value;
alert(editIds + "-" + note);
$.ajax({
type: 'POST',
url : '<?=Url::to(['batch-update'])?>',
data: {editIds: editIds, note: note},
success : function(data) {
window.location.href = 'batch-update'
}
});
This code sends editIds and note to my Controller actionBatchUpdate()
public function actionBatchUpdate() {
$ids = Yii::$app->request->post ( 'editIds' );
//$note = Yii::$app->request->post ( 'note' );
Yii::$app->request->setQueryParams([
'RescheduleSearch' => ['id' => implode(', ', $ids)],
]);
$searchModel = new RescheduleSearch ();
$dataProvider = $searchModel->search (Yii::$app->request->queryParams);
return $this->render ( 'batch-update', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
] );
$this->redirect ( [
'batch-update'
] );
This redirects to my batchUpdate page which is supposed to populate the searchModel with editIds and query all of them but what I am get is only a single value being queried (e.g. the last value if I redirect with queryParams.
public function search($params) {
$query = Parcel::find ()->where ( [
'parcel.user_id' => Yii::$app->user->id
] );
$query->joinWith ( [
'vehicle'
] );
// $query = Parcel::find();
$dataProvider = new ActiveDataProvider ( [
'query' => $query,
'pagination' => [
'pageSize' => 50
]
] );
$dataProvider->sort->attributes ['vehicle'] = [
// The tables are the ones our relation are configured to
// in my case they are prefixed with "tbl_"
'asc' => [
'vehicle.name' => SORT_ASC
],
'desc' => [
'vehicle.name' => SORT_DESC
]
];
$this->load ( $params );
if (! $this->validate ()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere ( [
'parcel.id' => $this->id,
'vehicle_id' => $this->vehicle_id,
'note' => $this->note,
'parcel.lat' => $this->lat,
'parcel.lng' => $this->lng,
'deliver_time' => $this->deliver_time,
'status' => $this->status,
'identifier' => $this->identifier,
'postal' => $this->postal,
'phone' => $this->phone
] );
$query->andFilterWhere ( [
'like',
'address',
$this->address
] )->andFilterWhere ( [
'like',
'note',
$this->note
] )->andFilterWhere ( [
'like',
'customer_name',
$this->customer_name
] );
$query->andFilterWhere ( [
'>',
'volume',
$this->volume
] )->andFilterWhere ( [
'>',
'weight',
$this->weight
] )->andFilterWhere ( [
'>',
'service_time',
$this->service_time
] )->andFilterWhere ( [
'>',
'window_start',
$this->window_start
] )->andFilterWhere ( [
'<',
'window_end',
$this->window_end
] );
$query->andFilterWhere ( [
'like',
'vehicle.name',
$this->vehicle
] );
return $dataProvider;
}
So my question is,how do I create a searchModel that can display only the checkbox ids that I have submitted with AJAX and display them on another page.
Thanks.