Redirect from one view to another view - Yii2

Choxx

This is my form in the view page of my website.

<?= $form->field($model, 'taskID')->textInput(['readonly' => true, 'value' => Yii::$app->getRequest()->getQueryParam('id')])  ?>   

<?php 
$ifDistributor = User::find()->select('userType')->where(['username'=>Yii::$app->user->identity->username])->andWhere(['userType'=>'Distributer'])->exists();
$ifDistributorHasOnSiteSupport = Distributorinfo::find()->select('hasOnSiteSupport')->where(['UName'=>Yii::$app->user->identity->username])->andWhere(['hasOnSiteSupport'=>1])->exists();
if($ifDistributor)
 if($ifDistributorHasOnSiteSupport)
    echo $form->field($model, 'assignedToID')->dropDownList(
        ArrayHelper::map(dektrium\user\models\User::find()
            ->select('username')
            ->where(['userType'=>'CCE-Distributer'])
            ->andWhere(['distributerID'=>Yii::$app->user->getId()])
            ->all(),'username','username'),['prompt'=>'Select Person']
    );
else {  
                Yii::$app->session->setFlash('error', 
                    "Invalid Page");
                //I WANT TO REDIRECT TO index.php?r=tasks/index THIS URL                    

}                      
?>
<?= $form->field($model, 'remarks') ?>
<?= $form->field($model, 'scheduledTime')->widget(DateTimePicker::classname(), [
                'options' => ['placeholder' => 'Enter event time ...'],
                'pluginOptions' => [
                    'autoclose' => true
                ]
            ])  ?>
<div class="form-group">
    <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>

As shown above in the else part, I want to redirect to tasks/index this url. Help me how can I do that in this View only.

Insane Skull

Use Url::to() and don't forget to add yii\helpers\Url in Header.

For Example,

return Yii::$app->response->redirect(Url::to(['path', 'id' => id]));

Redirect()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

yii2 - redirect from view to another view

How to redirect from a view in one app to a view in another?

Redirect from one Razor View to another Razor View

How to redirect from one view to another view in SwiftUI?

yii2 Getting array of data from one model and listing it in view of another

Django does not redirect from one view/url to another

How to redirect a page from one blueprint view to another?

How to redirect from view to another view

Yii2 - redirect if view file not exist

Yii2 Basic display create from from another model to a view from another model

Displaying data from one view in another view

Django - Redirect to another domain from View

How to redirect to another view from jQuery

redirect to view from another view NoReverseMatch error django

redirect to another view function

grails redirect to another view

Yii2 Activerecord not saved before redirect and shown in "view"

Load function from one view controller from another view controller

How to display data of another table in grid view in yii2?

Yii2, how to use another model for display in view file

xpage saving document from one view to another

Android : transfer a view from a parent to another one

Pass NSManagedObject from one view controller to another

Passing Context From One Django View To Another

pass view from one activity to another

Using variables from one View Controller in another

Is it possible to send a view from one Activity to another

Is it possible to copy constraints from one view to another?

Moving a view from a viewgroup to another one