Hey all. Today’s post is a response to a question asked today on IRC.
In zf1 within a controller I could do something like $this->getResponse()->setRedirect(‘/foo/bar’, 201) ~ How do I do that using zf2?
Controllers have plugins, not much has changed there. Except for the fact that it’s now even easier to get a redirect going. Check this out:
It also has a toUrl method, which behaves the same way:
Can you send a statusCode with that though?
Yes, you can. As seen here, the redirect returns a Response. A response has a setStatus code, thus allowing us to do this:
Happy coding 🙂