nemo
(Nemoneel)
January 26, 2011, 4:37pm
1
Hello,
In my model I use logic, if data not found then redirect to different page. I use this redirection code,
$this->redirect(array(‘author’));
Important note is that, I have two modules, and author comes from "abc" modules.
but redirection is not working. any idea?
CException
Description
Address does not have a method named "redirect".
gusnips
(Gustavo)
January 26, 2011, 4:44pm
2
Yii::app()->getController()->redirect('url');
nemo
(Nemoneel)
January 26, 2011, 5:04pm
3
Now I can redirect but I want to pass the value to the new page
Yii::app()->getController()->redirect("http://abc …com/abc/index.php?r=def/default/auther?systems=$this->systems");
I got this
http://abc …com/abc/index.php?r=def/default/auther?systems=Array
why I got array, I need the value there. Any idea
gusnips
(Gustavo)
January 26, 2011, 5:27pm
4
how could i know ? you defined the value of the variable you are trying to pass
the following is better
Yii::app()->getController()->redirect(array('def/default/auther',array('systems'=>$this->systems)));
anyway, even with this code the value will still be an array
jayrulez
(Waprave)
January 26, 2011, 7:17pm
6
You shouldn’t be doing a redirect in your model
tnorella
(Tony)
April 15, 2014, 7:54pm
7
where then is the best place to do a redirect?
Keith
(Kburton)
April 15, 2014, 8:09pm
8
You should really only redirect in the controller.
The model should handle your business rules. Some day you might want to use it in a non-web context, such as a console command, and the redirect would make no sense in that scenario.
The view should ideally do no more than display data formatted appropriately.
rudenich
(Rudenich)
April 15, 2014, 11:23pm
9
You can throw an exception in you model, and in controller in "try catch" implement logic of redirection
jkofsky
(Jkofsky)
April 16, 2014, 7:06am
10
nemo:
Hello,
In my model I use logic, if data not found then redirect to different page. I use this redirection code,
$this->redirect(array(‘author’));
the actual redirect logic should be in the control, as noticed above. Just to help.
$model = '/Get/your/data';
if (is_null($Model)) {
$this->redirect();
} else {
//Do whatever
}