【问题标题】:I want to redirect page in cakephp我想在 cakephp 中重定向页面
【发布时间】:2012-07-24 12:24:18
【问题描述】:

我有网址:-

http://mydomain/test/index.html

我希望用户在 url 中输入这个:- http://mydomain/test

它将重定向到http://mydomain/test/index.html..

我尝试过的我在路由中给出了代码。

Router::connect('/', array('controller' => 'enrollments', 'action' => 'index'));

我想重定向到 index.html 页面如何给..

【问题讨论】:

  • index.html 页面到底在哪里?你把它放在 app/webroot/test/ 吗?
  • 您无法在 webroot 中访问 index.html。 index.php 优先且不能删除,否则 CakePHP 将停止工作。为什么你仍然需要一个静态的 html 文件,你不能将它添加为一个静态的 CakePHP 动作并将根重定向到那个?
  • @Juhana 有没有办法做到这一点..
  • 我已经给the duplicate写了一个答案。请不要转发问题。
  • 为此使用PagesController。当这已经是 CakePHP 核心的一部分时,实现自定义控制器来提供静态内容是没有意义的。

标签: cakephp-1.3


【解决方案1】:

Pages Controller 通常用于提供静态页面。例如。如果您制作了一个视图文件 *app/views/pages/about_us.ctp*,您可以使用 url *http://example.com/pages/about_us* 访问它。

如果您有baked your app,页面控制器应该已经复制到您的app/controllers/ 文件夹并且能够修改它,或者您可以将pages_controller.php 从核心复制到您的应用程序。但是,如果您不需要修改它,即只显示静态内容,您不需要将页面控制器复制到 app/controllers/

如何显示静态页面?

如果您创建了一个视图文件app/views/pages/index.ctp,您可以使用网址http://example.com/pages/index 访问它。然后修改路线可以:

Router::connect('/test', array('controller' => 'pages', 'action' => 'display', index));

但是,这不会提供http://www.example.com/test/index.html,而是:http://www.example.com/test/index

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-09
  • 1970-01-01
  • 2016-09-03
  • 2011-04-01
相关资源
最近更新 更多