Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 找不到CodeIgniter对象只有索引函数起作用_Php_Html_Codeigniter - Fatal编程技术网

Php 找不到CodeIgniter对象只有索引函数起作用

Php 找不到CodeIgniter对象只有索引函数起作用,php,html,codeigniter,Php,Html,Codeigniter,我是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 $r

我是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');
        }
    }
?>

我必须在视图文件夹中添加两个文件,它们的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

  • 您可以将此设置为空
    $config['base\u url']=''
  • 使用index.php文件检查根文件夹中的.htaccess
  • 检查mod_rewrite apache模块是否已启用
  • 重新编写引擎打开
    重写基/
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    
    RewriteRule^(.*)$index.php/$1[L]

    遵循Furqan提到的步骤,但如果不起作用,请在.htaccess文件(项目根目录)中尝试此操作:

    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]
    

    thanx我去了apache,但我仍然不明白.htaccess到底是怎么回事。问题是我已经像这样删除了congfig上的index.php($config['index_page']='')。我所要做的就是像($config['index_page']='index.php';)一样输入index.php。
    DirectoryIndex index.php
    
    Options -Indexes
    
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]