I have a controller that has a method. The code is too long in the method, so I have put some of the codes in other private methods, so that methods become understandable and not make a mess out of it.
Now, when I access the public method from the URL, depending on parameters, it will call a specific private method to process the job. After the job is processed, I want to redirect to a URL, but the redirection is not working.
A sample of my code is as follows:
class SomeClass extends BaseController{
public function getMethodName()
{
//check the params and choose a private method to call
$this->processJob();
}
private function processJob()
{
//process the job and redirect at the end
return Redirect::to('some/url');
}
}
The problem is, the above redirect does not work. Why is that? In Codeigniter, when you used redirect
it works nomatter where it is called from.
If the above code sample is not the right way to do it, would appreciate if someone could show me how it is to be done. Thanks.
You have to return the return from $this->processJob()
too.
class SomeClass extends BaseController{
public function getMethodName()
{
//check the params and choose a private method to call
return $this->processJob();
}
private function processJob()
{
//process the job and redirect at the end
return Redirect::to('some/url');
}
}
You can try to redirect to another page from your public function, according to your private function result (I think it's a better solution to make your code more human readable). But it could works like you wrote it ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With