Codeigniter-如何在删除index.php后加载新页面 [英] Codeigniter- how load new page after removing index.php

查看:58
本文介绍了Codeigniter-如何在删除index.php后加载新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是codeIgniter的新手。我的索引文件中有一些链接。
我已经从网址中删除了index.php,所以现在的网址看起来像

I am new to codeIgniter. I have some links in my index file. I have removed index.php from url so now url look like

http:// localhost / app / Loader / demo_page

如果我的加载器代码为:

This if my Loader code:

class Loader extends CI_Controller {

    public function __construct(){
        parent::__construct();
        $this->load->helper('url');
    }
    public function index()
    {
        $this->load->view('header');
        $this->load->view('center');
        $this->load->view('footer');
    }
    public function demo_page()
    {
        $this->load->view('demo');
    }
}

当我单击此链接时,找不到错误。

When I click on this link, I get not found error.

现在我该怎么办?

我也要从url中删除控制器名称,并希望仅显示类似domain / app / mydemopage.php的url。
请帮助。

I want to remove controller name also from url and want to show pretty url only like domain/app/mydemopage.php. Please help.

推荐答案

您可以使用以下示例更改路由文件。在字符串中,我传递了控制器和函数(方法)的名称。在$ route数组中,我可以随意传递漂亮的名字。

You can change your route file using below example. In string I am passing controller and function (method) name. And in $route array I am passing pretty name as I like.

#Route file path : CI_project/applications/config/routes.php

$route['default_controller'] = "Dashboard";
$route['contact-us'] = "dashboard/contact_us";

但是请记住,如果要使上面的代码起作用,必须启用重写模块,然后

But please keep in mind that if you want to make above code work you have to enable rewrite module and give this code in .htaccess.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /prjectName/
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
 # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: Pawan Nagar
<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule> 

这篇关于Codeigniter-如何在删除index.php后加载新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆