简体   繁体   中英

Error 404 when trying to access a controller in CodeIgniter

I'm trying to access a CodeIgniter controller and I'm getting a 404 error. In my computer, I can access .../index.php/apadrinhamentoController/padrinhosPossiveis

but when uploaded to the server, I can just access the index file, in the site.com/apadrinhamento/index.php and not site.com/apadrinhamento/index.php/apadrinhamentoController (Get 404 error).

apadrinhamentoController.php File

<?php
class apadrinhamentoController extends CI_Controller{
public function __construct() {
    parent::__construct();
    $this->load->helper('url');
}
public function index() {
    $this->load->view('apadrinhamento');
}
}

index.php file is default from CodeIgniter

I'm not using a .htaccess on /apadrinhamento

First of all you should understand, Codeigniter != CakePHP . Means you no need to define controller_name + Controller word.

class apadrinhamento extends CI_Controller
{
    public function __construct() 
    {
        parent::__construct();
        $this->load->helper('url');
    }
    public function index() 
    {
        //$this->load->view('apadrinhamento');
        echo 'Im index of your function';
    }

    public function my_method() 
    {
        echo 'I jsut access my_Method';
    }

}

and in config/routes.php

$route['default_controller'] = "";//Default Controller Name
$route['404_override'] = '';

and

to access your controller(above)

site.com/apadrinhamento/ //this will access index() function
//or
site.com/index.php/apadrinhamento/

if you want to access the method inside it(URL Should be)

site.com/apadrinhamento/my_method
//or
site.com/index.php/apadrinhamento/my_method

Note if you not place .htaccess then url should be site.com/index.php/apadrinhamento/

问题是在CodeIgniter v3.0中,我们需要编写以大写字母开头的控制器文件名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM