Reputation: 67
is there a way to make a redirection from inside a phtml file in ZF2 Framework?
The reason is that I am using the jQuery $.POST mechanism (ajax) to refresh a part of the page, but I cannot make a redirection from the controller used by the ajax because it will load the new page into the div (which is inside another page).
I have tried using ZF2's :
$this->_redirect($this->url('restaurants'));
But I get a ServiceNotFoundException. I also tried php's:
<?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?>
But this just did not work at all.
Hope this is clear enough!.. Any help is much appreciated!
Upvotes: 0
Views: 942
Reputation: 4616
You can't use header
when you printed anything before it. There must not be any output before header
. So this means the exact same for $this->_redirect()
.
What you could do is the following:
Add this to your head
section
<meta http-equiv="refresh" content="0; url=http://example.com/">
or use javascript to redirect the user. If you don't want to extend your layout file you should use javascript:
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
EDIT
After rereading your question i think the only possible way for you to redirect the user after you've received the page content is the javascript solution.
Upvotes: 1