i have a search result page and another form on it. when i get the result on this page i am submitted an enquiry form and want to get back on the page with different layout. my search function is:
public function actionFind()
{
$GOR = new OnroadRequest();
if(Yii::$app->request->post())
{
$data = $_POST;
if($_POST['brand_id'] != ''){
$brand_id = $_POST['brand_id'];
}
else{
$brand_id = '';
}
if($_POST['city_id'] != ''){
$city_id = $_POST['city_id'];
}
else{
$city_id = '';
}
if($_POST['model_id'] != ''){
$model_id = $_POST['model_id'];
}
else{
$model_id = '';
}
if(isset($_POST['variant_id'])){
$variant_id = $_POST['variant_id'];
}
else{
$variant_id = '';
}
$getonroad = VariantOnroadprice::find()->where('city_id = '.$city_id.' and model.id = '.$model_id.' and model.brand_id = '.$brand_id.'')->joinWith('model')->joinWith('city')->asArray()->one();
if($getonroad != '')
{
if(isset($getonroad['model'])){
$getonroad['galleries'] = Gallery::find()->where('model_id = '.$getonroad['model']['id'].' and group_id = 4')->select('image')->asArray()->one();
$getonroad['galleries']['count'] = Gallery::find()->where('model_id = '.$getonroad['model']['id'].' and (group_id = 1 or group_id = 2)')->count('image');
}
}
return $this->render('find',[
'getonroad' => $getonroad,
'GOR' => $GOR,
'brand_id'=>$brand_id,
'city_id'=>$city_id,
'model_id'=>$model_id,
'variant_id'=>$variant_id,
]);
}
else
{
return $this->render('find',[
'GOR' => $GOR,
]);
}
}
and my form function is :
public function actionAdd(){
$GOR = new OnroadRequest();
if ($GOR->load(Yii::$app->request->post()))
{
if($GOR->phone_id != ''){
$phone = Phone::find()->where('phone = '.$GOR->phone_id.'')->asArray()->one();
if($phone == ''){
$phone = new Phone();
$phone->phone = $GOR->phone_id;
if($phone->save()){
$GOR->phone_id = $phone->id;
}
}
else{
$GOR->phone_id = $phone['id'];
}
}
if($GOR->save()){
return $this->render('result', [
'GOR' => $GOR,
]);
}
else{
Yii::$app->getSession()->setFlash('error', 'Unable to save.');
return $this->redirect('find', [
'GOR' => $GOR,
]);
}
}
else
{
return $this->render('index', [
'GOR' => $GOR,
]);
}
}
now this find function is working fine. and the add function is also submitting data to db. but after submitting the add function i dont get my previous searched data or the variable. so how do i resolve it.
P.S. i have used $_POST because the i cant create any object which has attributes like i want to be in search filter. and do recommend any method to get the form data of html helper form without active object. thanks in advance