我是CodeIgniter的新手,一切都很顺利,直到我发现我只能调用index()
函数。
我已经按预期设置了config.php
, autoload.php
和routes.php
。
在config.php
$config['base_url'] = 'http://localhost/ci';
$config['index_page'] = '';
在autoload.php
$autoload['helper'] = array('form','url');
在routes.php
$route['default_controller'] = "site";
我有一个名为site的控制器
<?php
class Site extends CI_Controller{
function index(){
$this->load->view('home');
}
function new_method(){
$this->load->view('home2');
}
}
?>
我有2个文件在视图文件夹与他们的HTML代码,简单地命名为home.php和home2.php
在home。php中有
<?php
echo form_open('site/new_method');
echo form_submit('submit', 'call method');
echo ('<br /><br />');
echo anchor('site/new_method', 'call method');
echo form_close();
?>
index()加载,结果你得到一个按钮和一个链接,但当我点击我给出找不到对象!错误404
遵循Furqan提到的步骤,但如果这不起作用,请在您的.htaccess文件(在项目的根目录下)中尝试以下操作:
RewriteEngine on
RewriteCond $1 !^(index'.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
- 您可以将此设置为空
$config['base_url'] = '';
- 用index.php文件检查根目录下的。htaccess
- 检查mod_rewrite apache模块是否启用
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Check the uri_protocol in the config file that should be AUTO.
Config/config.php ===> $config['uri_protocol'] = 'AUTO';
在根目录下创建一个.htaccess文件,并在其中写入以下代码:
DirectoryIndex index.php
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
我有这个问题,但它是由将项目从窗口移动到linux引起的,我通过编写控制器来解决这个问题。示例http://localhost/AppController/blog代替http://localhost/appcontroller/blog谢谢!