【问题标题】:CodeIgniter object not found only the index function works未找到 CodeIgniter 对象仅索引函数有效
【发布时间】:2013-06-06 15:34:57
【问题描述】:

我是 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 的控制器

<?php

    class Site extends CI_Controller{

        function index(){
            $this->load->view('home');
        }

        function new_method(){
            $this->load->view('home2');
        }
    }
?>

我必须在 view 文件夹中使用它们的 HTML 代码来创建 2 个文件,它们的名称简单地命名为 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

【问题讨论】:

    标签: php html codeigniter


    【解决方案1】:

    按照 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]
    

    【讨论】:

      【解决方案2】:
      1. 你可以把它设为空$config['base_url'] = '';
      2. 使用 index.php 文件检查根文件夹中的 .htaccess
      3. 检查 mod_rewrite apache 模块是否启用

      RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]

      【讨论】:

      • thanx 我去过 apache,但我仍然不明白 .htaccess 发生了什么。问题是我已经像这样($config ['index_page'] ='';)那样删除了配置上的index.php。我所要做的就是像 ($config['index_page'] = 'index.php';) 一样输入 index.php。
      【解决方案3】:
      Check the uri_protocol in the config file that should be AUTO.
      
      Config/config.php ===> $config['uri_protocol']  = 'AUTO';
      

      【讨论】:

        【解决方案4】:

        在您的根目录中创建一个 .htaccess 文件并在其中编写以下代码。

        DirectoryIndex index.php
        
        Options -Indexes
        
        RewriteEngine on
        
        RewriteCond %{REQUEST_FILENAME} !-f
        
        RewriteCond %{REQUEST_FILENAME} !-d
        
        RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-04-02
          • 2022-07-15
          • 2021-05-22
          • 2018-10-27
          • 2019-04-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多