在codeigniter中找不到404文件

时间:2015-10-26 06:50:11

标签: php codeigniter

我是CodeIgniter MVC的新手。我的主视图已正确加载。当我在index()中用home替换home时,它正在工作,但是当我调用aboutus函数时,它显示404 file not found错误。登录也正常。我没有弄错。我的视图文件夹包含aboutus,home和login文件。

SQL> SELECT TO_CHAR(SYSDATE, 'DD-MON-RR', 'nls_date_language=english') dt FROM DUAL;

DT
---------
26-OCT-15

//这里是html代码

public function index()
    {

    $this->load->view("home"); 

}
    function login()
{

    $this->load->view("login"); 

}
function aboutus()
{

    $this->load->view("aboutus"); 

}

5 个答案:

答案 0 :(得分:1)

如何加载默认控制器

config/routes.php

$route['default_controller'] = "controller_name; //this load index() in provided controller
$route['default_controller'] = "controller_name/method_name"; //this load method which you created inside provided controller(ex: main/about_us)

如何创建控制器

路径 - application/controllers/ 文件名 - main.php
main.php

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Main extends CI_Controller {

    public function index()
    {
        $this->load->view("home"); 
    }

    function login()
    {
        $this->load->view("login"); 
    }

    function aboutus()
    {
        $this->load->view("aboutus"); 
    }

}

如何制作视图

Path - `application/view/`
File name - `home.php`
File name - `login.php`
File name - `aboutus.php`

如何使用链接

<a href="<?php echo base_url()?>main/home">Home</a>
<a href="<?php echo base_url()?>main/login">Login</a>
<a href="<?php echo base_url()?>main/aboutus">aboutus</a>

如何使用base_url()

config/autoload.php

中的

$autoload['helper'] = array('url');
config/config.php

中的

$config['base_url'] = '';

答案 1 :(得分:0)

像这样更改你的HTML

<a href="<?php echos site_url('controllerName/yourfunction');?>">home</a>
<a href="<?php echos site_url('controllerName/aboutus');?>">about us</a>

答案 2 :(得分:0)

您需要在routes.php

中添加路线到新功能aboutus()

您可以在“application / config /”中找到routes.php。 假设您的控制器名称为'Client_home' 然后, 例如:$route['default_controller'] = 'Client_home';

当你在index()中用home替换home时,这就是为什么aboutus工作的原因。如果您没有指定要启动的功能,则默认情况下将调用index()方法。

对于aboutus()方法/函数,路由将如下所示: 例如:$route['aboutus'] = "Client_home/aboutus";

Synatx:

$route['url'] = "controllername/method or function name"

答案 3 :(得分:0)

此问题的示例。希望这能帮到你:

http://localhost/ciexample/index.php/your_controller/your_function

答案 4 :(得分:0)

我想知道控制器名称,也想知道你在哪里更改了它的配置,如果是,那么就是配置。

在地址栏中使用此功能 &#34;本地主机/ folder_name_of_the_project /索引/ CONTROLLER_NAME&#34;