views:

1008

answers:

4

I have a module built in CakePHP that is hosted within an iFrame. I need to have a redirect target the parent page. Using normal HTML I do:

<a href="#" target="_parent">

But how do I do that for CakePHP redirect?

$this->redirect('http://www.url.com');
+2  A: 

A "redirect" is actually done using the HTTP protocol, meaning it's totally transparent to the user and no HTML is loaded.

What you are trying to do is create a link in an HTML page. So, you can't use redirect() to do this, because redirect() uses a lower layer than HTML.

You'll have to create a page with an HTML redirect (there are several ways to do this, google will help you).

FWH
A: 

Taking a stab at an answer:

$this->redirect() redirects by issuing an HTTP response code, i.e. the HTTP header will make the browser redirect. There's no concept of a "target" in HTTP response codes, so you can't redirect a parent frame using this technique.

Your user will have to click on a target="_parent" link himself, or you have to use other techniques.

deceze
A: 

i have one related question how to redirect with parameter ie i can do $this->redirect(array('controller' => 'pages', 'action' => 'display', ????));

in the question mark place i need one parameter which will be corresponding to the post id so that i can display that page....how can i redirect this way

cakecoder
You should better ask this as a new question, more people would look at it and try to help you. (And it's not an answer to this question, so not very helpful here in that respect.)
sth
Yes, you can (and should) redirect that way. You can also pass a parameter:$this->redirect(array('controller'=>'pages', 'action'=>'display', 1));
harpax
A: 

Try $this->redirect(array('controller' => 'pages', 'action' => 'display', $id)); where $id is the id of the post you want to redirect to.

George
sorry, this was a solution to cakecoder's question
George