Routes in not redirect to index.html page

旧街凉风 提交于 2019-12-23 04:22:58

问题


I am coding on cakephp 1.3. I have a problem redirecting the page to index.html.

My index.html is inside webroot folder. What I know cakephp will directly redirect to index.html.

When I using URL it is showing error..

Error: Controller could not be found.

Error: Create the class Controller below in file: app/controllers/controller.php

<?php
class Controller extends AppController {

    var $name = '';
}
?>

I have followed some link but it not seems to work. I have checked on Google also.

How can I append .html to all my URLs in cakephp?


回答1:


You can't replace CakePHP's own index.php or CakePHP will stop working. Normally you can put files in webroot and it would work without problems, but the root file is a bit more trickier, since (AFAIK) you can't use Cake's routing only to display a non-CakePHP file.

Put your html file in a view in any controller and route the root directory there. For example, name the file index.ctp and put it in app/views/static_pages/index.ctp.

Router:

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

Controller (static_pages_controller.php):

class StaticPagesController extends AppController {
    function index() {
        // no need to do anything except use no layout file
        $this->layout = false;
    } 
}

Model (static_page.php):

class StaticPage extends AppModel {
    // don't use a database for this model
    var $useTable = false;
}


来源:https://stackoverflow.com/questions/11630018/routes-in-not-redirect-to-index-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!