没有找到CodeIgniter对象只有索引函数有效 [英] CodeIgniter object not found only the index function works
问题描述
我是CodeIgniter的新手,一切都很顺利,直到我发现我只能调用 index()
函数。
I am new to CodeIgniter, everything was going fine and well up until I found out that I can only make a call to the index()
function.
我已经设置了 config.php
, autoload.php
和 routes.php
与预期的一样。
I have setup the config.php
, autoload.php
and routes.php
as expected.
在config.php上
on the config.php
$config['base_url'] = 'http://localhost/ci';
$config['index_page'] = '';
关于autoload.php
on the autoload.php
$autoload['helper'] = array('form','url');
关于routes.php
on the routes.php
$route['default_controller'] = "site";
我有一个名为site的控制器
I have a controller named site
<?php
class Site extends CI_Controller{
function index(){
$this->load->view('home');
}
function new_method(){
$this->load->view('home2');
}
}
?>
我必须使用HTML代码在视图文件夹上创建2个文件,简单地命名为home.php和
home2.php
I have to 2 files on the view folder with their HTML code, simply named home.php and home2.php
在home.php上我有
on home.php I have
<?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();
?>
索引()加载,因为结果U得到一个按钮和一个链接,但是当我点击我时给出
对象未找到!错误404
The index() loads, as results U get a button and a link but when I click I am given Object not found! Error 404
推荐答案
- 您可以使这个空
$ 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]
这篇关于没有找到CodeIgniter对象只有索引函数有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!