Yii Framework Forum: Redirect To First Controller/action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Redirect To First Controller/action after saving or updating Rate Topic: -----

#1 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 28 April 2013 - 10:13 AM

Hi to Everyone

I have an action (controllerF/actionF) that permits the user to save a model by redirect to another action (controllerA/actionA). The user can be update the model after of submit.

how can redirect the user after saving to the first controllerF/actionF ?


note the actionA can be used directly, so I can't use
$this->redirect(array('controllerA/actionA'))

I tried to do that with

Yii::app()->user->setReturnUrl
Yii::app()->request->urlReferrer;
Yii::app()->user->returnUrl;


but without luck

can anyone advice me a way to do that?
thanks!
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#2 User is offline   antares 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-September 12

Posted 29 April 2013 - 01:32 AM

You will be able to use a function redirect($url)
class controllerF extend Controller
{
  public function actionF()
  {
     .....
     $this->redirect($url);
  }
}

0

#3 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 29 April 2013 - 03:21 AM

View Postantares, on 29 April 2013 - 01:32 AM, said:

You will be able to use a function redirect($url)
class controllerF extend Controller
{
  public function actionF()
  {
     .....
     $this->redirect($url);
  }
}



Hi antares, thanks for response
But your code redirects to another action that I want (first step).
how can I redirect from the redirected action back to the first controller/action after of saving with dynamically way? (and after of two requests)

Thanks
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#4 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 29 April 2013 - 05:13 AM

View PostKonApaz, on 29 April 2013 - 03:21 AM, said:

Hi antares, thanks for response
But your code redirects to another action that I want (first step).
how can I redirect from the redirected action back to the first controller/action after of saving with dynamically way? (and after of two requests)

Thanks



is it u need another action ?

use a common method (function) inside the 2 actions. Thats the good programming practice.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#5 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 29 April 2013 - 08:00 AM

View PostRajith R, on 29 April 2013 - 05:13 AM, said:

is it u need another action ?

use a common method (function) inside the 2 actions. Thats the good programming practice.



Hi Rajith

the second action belongs to another controller and can be used also as independent action

for example an eshop user can be either modified his contact information directly from user profile, or in the step of choosing shipping Methods.
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#6 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 29 April 2013 - 08:50 AM

ControllerF extends Controller {

    public function actionFirst()
    {
        Yii::app()->user->setState('quickRedirect', 'thisControllersActionPath');
        // Redirect to ControllerA
    }
}

ControllerA extends Controller {

    public function actionSecond()
    {
        if (Yii::app()->user->getState('quickRedirect'))
        	// Redirect to Yii::app()->user->getState('quickRedirect')
    }
}

0

#7 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 30 April 2013 - 03:14 PM

View Postwaterloomatt, on 29 April 2013 - 08:50 AM, said:

ControllerF extends Controller {

    public function actionFirst()
    {
        Yii::app()->user->setState('quickRedirect', 'thisControllersActionPath');
        // Redirect to ControllerA
    }
}

ControllerA extends Controller {

    public function actionSecond()
    {
        if (Yii::app()->user->getState('quickRedirect'))
        	// Redirect to Yii::app()->user->getState('quickRedirect')
    }
}



Hi waterloomatt

I suspect that your way is the only way! (due to more than one session requests)

The solution I chose is:

 if ($model->save()) {
                if (Yii::app()->user->hasState('myRedirect'))
                     $this->redirect(Yii::app()->user->getState('myRedirect'));
                else if (Yii::app()->user->returnUrl)
                    $this->redirect(Yii::app()->user->returnUrl);
                else
                    $this->redirect(('default'));
            }


Thanks :)
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users