redirect from my model


In my model I use logic, if data not found then redirect to different page. I use this redirection code,


Important note is that, I have two modules, and author comes from "abc" modules.

but redirection is not working. any idea?



Address does not have a method named "redirect".


Now I can redirect but I want to pass the value to the new page


I got this


why I got array, I need the value there. Any idea

how could i know ? you defined the value of the variable you are trying to pass

the following is better


anyway, even with this code the value will still be an array

wow, great working. :rolleyes:


You shouldn’t be doing a redirect in your model

where then is the best place to do a redirect?

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.

You can throw an exception in you model, and in controller in "try catch" implement logic of redirection

the actual redirect logic should be in the control, as noticed above. Just to help.

$model = '/Get/your/data';

if (is_null($Model)) {


} else {

   //Do whatever