Generally we can go to one action to another action by using
$this->redirect('.....');
But if we need to pass some value or object from one action to another action then how it can be done? coz there is no option for passing any object in redirect.
There is session but use of frequent sessions can put some extra load on the server. What are the possible alternatives for this in Yii?
public function actionXX(){
$_GET['someKey'] = $anyVal ;
$this->forward('someRoute',false);
unset($_GET['someKey']);
}
may can use the $_GET/$_POST… global variable to pass params , or some another global shared component to pass param (Yii::app()->params[‘someKey’] ? ) . just my thought hope you find a better solution .
Lets say the action being performed is the update action, and you want to redirect to the "view" action, passing along the id of the model just updated. Then do this:
Also, (regarding Maclein’s response) avoid directly referring to $_GET and $_POST. Yii frees you from that, by allowing you declare variables in the function declaration for any action. If you still need to refer to the get or the post, do it safely, by defining a default value in the event the variable is missing from the get/post:
// GET
$foo = Yii::app()->request->getQuery('foo', 0);
// Post
$foo = Yii::app()->request->getPost('foo', 0);
// GET *OR* POST
$foo = Yii::app()->request->getParam('foo', 'defaultValue');
Thanks for the reply… it is really good… and sounds descent as a solution. Thanks.
@Emily One more thing if you can suggest, what are the possible ways to maintain(or keep alive) chain life cycle of request objects in Yii?? Please tell me with some example.
public function actionSomething($x) {
// If $x was either on the POST or the GET, it's value will be set, so you can reference $x
// If $x was not on the POST or the GET, you'll get a run-time error.
}
No actually that was my fault totally… I was doing something wrong over there and thinking that filter is failing to keep alive the requested objects. I put there some checking and got it was not coming in either cases. Its a silly mistake. Now that’s fine…
@Emily What I was trying to do is that I wanted to make clean the url. But it was giving so much errors and rest of the pages are not working. What I have done is that