Reputation: 23
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
Upvotes: 0
Views: 4702
Reputation: 23
The problem was that in CodeIgniter v3.0 we need to write controller files names starting with capital letters.
Upvotes: 1
Reputation: 38584
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 besite.com/index.php/apadrinhamento/
Upvotes: 2