php - 找不到 CodeIgniter 对象 只有索引函数有效

标签 php html codeigniter

我是 CodeIgniter 的新手,一切都很顺利,直到我发现我只能调用 index() 函数。

我已经按预期设置了 config.phpautoload.phproutes.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/

相关文章:

十万和千万的 PHP 格式

php - 使用 cURL 检索 JSON 数据以与 jQuery 一起使用

PHP 内爆具有增量值

php - 使用 Codeigniter 表库时将数据传递到 Twitter Bootstrap Modal

php - 正则表达式验证以包含 jquery 的 Enter 键

html - CSS 在使用文本溢出时阻止 DIV 换行 : ellipsis

android - HTML5可以访问原生组件吗

html - 如何制作一个文本框,在文本前面有一个方 block ,带有链接

php - 使用下拉菜单进行编辑 - Codeigniter

php - Mysqli 错误停止程序执行