路由不重定向到index.html页面 [英] Routes in not redirect to index.html page
问题描述
我在cakephp 1.3上编码。我将页面重定向到index.html时遇到问题。
I am coding on cakephp 1.3. I have a problem redirecting the page to index.html.
我的index.html位于webroot文件夹中。
我所知道的cakephp将直接重定向到index.html。
My index.html is inside webroot folder. What I know cakephp will directly redirect to index.html.
当我使用URL时,它显示错误。
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 = '';
}
?>
我关注了一些链接,但似乎不起作用。
我也在Google上检查过。
I have followed some link but it not seems to work. I have checked on Google also.
推荐答案
您不能替换CakePHP自己的index.php,否则CakePHP将停止工作。通常,您可以将文件放在webroot中,并且可以正常工作,但是根文件要复杂一些,因为(AFAIK)您不能仅使用Cake的路由来显示非CakePHP文件。
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.
将html文件放在任何控制器的视图中,并将根目录路由到该位置。例如,将文件命名为index.ctp并将其放在app / views / static_pages / index.ctp中。
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'));
控制器(static_pages_controller.php):
Controller (static_pages_controller.php):
class StaticPagesController extends AppController {
function index() {
// no need to do anything except use no layout file
$this->layout = false;
}
}
模型(static_page.php):
Model (static_page.php):
class StaticPage extends AppModel {
// don't use a database for this model
var $useTable = false;
}
这篇关于路由不重定向到index.html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!