我是 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 的 Controller
<?php
class Site extends CI_Controller{
function index(){
$this->load->view('home');
}
function new_method(){
$this->load->view('home2');
}
}
?>
我必须在 View 文件夹中放置 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]
关于php - 找不到 CodeIgniter 对象 只有索引函数有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16966290/