如何使用cakephp呈现.html文件:CakePHP

时间:2014-09-02 07:08:22

标签: cakephp-2.0

我正在开发CakePHP,我有一个网址http://admin.example.com/Pages 如何创建http://admin.example.com/Pages.html?有没有解决这个问题的解决方案或组件?

2 个答案:

答案 0 :(得分:1)

根据CakeBook,您可以定义要在路径中解析的扩展名

E.g。在app/Config/routes.php

中写下面的代码
Router::parseExtensions('html');

这将允许您在路径(url)中发送.html扩展

不创建链接

例如:

$this->Html->link('Link title', array(
                    'controller' => 'pages',
                    'action' => 'index',
                    'ext' => 'html'
                ));

当您点击该链接时,您将在浏览器中获得类似此内容的网址

http://admin.example.com/pages/index.html

答案 1 :(得分:0)

你真的需要这个吗? CakePHP自动呈现View文件夹

中的视图文件
  1. 您可以在PagesController文件夹中创建(如果是indexindex.ctp methond)app/View/Pages,它将自动呈现。
  2. 您可以使用file_get_contents函数来读取文件。像这样:

    //在控制器中 function index(){
       $ content = file_get_contents(' path / to / file.html');
       echo $ content;
       模具();
    }