![](/img/trans.png)
[英]Page not found error when trying to access index controller in Codeigniter
[英]Error 404 when trying to access a controller in CodeIgniter
我正在嘗試訪問CodeIgniter控制器,但出現404錯誤。 在我的計算機上,我可以訪問.../index.php/apadrinhamentoController/padrinhosPossiveis
但是當上傳到服務器時,我只能訪問site.com/apadrinhamento/index.php
的索引文件,而不是site.com/apadrinhamento/index.php/apadrinhamentoController
的索引文件(獲取404錯誤)。
apadrinhamentoController.php
文件
<?php
class apadrinhamentoController extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index() {
$this->load->view('apadrinhamento');
}
}
CodeIgniter默認提供index.php
文件
我不在/apadrinhamento
上使用.htaccess
首先,您應該了解Codeigniter != CakePHP
。 意味着您無需定義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';
}
}
並在config/routes.php
$route['default_controller'] = "";//Default Controller Name
$route['404_override'] = '';
和
訪問您的控制器(以上)
site.com/apadrinhamento/ //this will access index() function
//or
site.com/index.php/apadrinhamento/
如果要訪問其中的方法(URL應該是)
site.com/apadrinhamento/my_method
//or
site.com/index.php/apadrinhamento/my_method
請注意,如果您未放置
.htaccess
則網址應為site.com/index.php/apadrinhamento/
問題是在CodeIgniter v3.0中,我們需要編寫以大寫字母開頭的控制器文件名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.