如何将目标参数传递给CakePHP重定向?

时间:2022-11-09 07:24:59

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:

我有一个内置在CakePHP中的模块,它在iFrame中托管。我需要在父页面上有一个重定向目标。使用普通的HTML我做:

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

But how do I do that for CakePHP redirect?

但是我如何为CakePHP重定向做到这一点?

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

3 个解决方案

#1


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

“重定向”实际上是使用HTTP协议完成的,这意味着它对用户完全透明,并且不加载HTML。

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.

您要做的是在HTML页面中创建一个链接。因此,您不能使用redirect()来执行此操作,因为redirect()使用的是比HTML更低的层。

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

你必须创建一个带有HTML重定向的页面(有几种方法可以做到这一点,谷歌会帮助你)。

#2


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.

$ this-> redirect()通过发出HTTP响应代码重定向,即HTTP标头将使浏览器重定向。 HTTP响应代码中没有“目标”的概念,因此您无法使用此技术重定向父框架。

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

您的用户必须自己单击target =“_ parent”链接,否则您必须使用其他技术。

#3


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

尝试$ this-> redirect(array('controller'=>'pages','action'=>'display',$ id));其中$ id是您要重定向到的帖子的ID。

#1


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

“重定向”实际上是使用HTTP协议完成的,这意味着它对用户完全透明,并且不加载HTML。

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.

您要做的是在HTML页面中创建一个链接。因此,您不能使用redirect()来执行此操作,因为redirect()使用的是比HTML更低的层。

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

你必须创建一个带有HTML重定向的页面(有几种方法可以做到这一点,谷歌会帮助你)。

#2


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.

$ this-> redirect()通过发出HTTP响应代码重定向,即HTTP标头将使浏览器重定向。 HTTP响应代码中没有“目标”的概念,因此您无法使用此技术重定向父框架。

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

您的用户必须自己单击target =“_ parent”链接,否则您必须使用其他技术。

#3


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

尝试$ this-> redirect(array('controller'=>'pages','action'=>'display',$ id));其中$ id是您要重定向到的帖子的ID。