php 未找到 CodeIgniter 对象,只有索引功能有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16966290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter object not found only the index function works
提问by immanuelx
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.
我是 CodeIgniter 的新手,一切都很顺利,直到我发现我只能调用该index()
函数。
I have setup the config.php
, autoload.php
and routes.php
as expected.
我已经设置了config.php
,autoload.php
和routes.php
预期的一样。
on the config.php
在 config.php 上
$config['base_url'] = 'http://localhost/ci';
$config['index_page'] = '';
on the autoload.php
在 autoload.php 上
$autoload['helper'] = array('form','url');
on the routes.php
在routes.php
$route['default_controller'] = "site";
I have a controller named site
我有一个名为 site 的控制器
<?php
class Site extends CI_Controller{
function index(){
$this->load->view('home');
}
function new_method(){
$this->load->view('home2');
}
}
?>
I have to 2 files on the view folder with their HTML code, simply named home.php and home2.php
我必须使用它们的 HTML 代码在视图文件夹中创建 2 个文件,简单地命名为 home.php 和 home2.php
on home.php I have
在 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();
?>
The index() loads, as results U get a button and a link but when I click I am given Object not found! Error 404
index() 加载,结果你得到一个按钮和一个链接,但是当我点击时,我得到了找不到对象!错误 404
采纳答案by Furkat U.
- You can make this empty
$config['base_url'] = '';
- Check .htaccess in root folder with index.php file
- Check mod_rewrite apache module is enabled
- 您可以将其设为空
$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]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
回答by Richard Lovell
Follow the steps that Furqan mentioned, but if that doesn't work, try this in your .htaccess file (in the root of your project):
按照 Furqan 提到的步骤进行操作,但如果这不起作用,请在您的 .htaccess 文件(在您的项目的根目录中)尝试此操作:
RewriteEngine on
RewriteCond !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/ [L]
回答by vinod
Check the uri_protocol in the config file that should be AUTO.
Config/config.php ===> $config['uri_protocol'] = 'AUTO';
回答by Aditya Tomar
create a .htaccess file inside your root directory and write the below code there.
在根目录中创建一个 .htaccess 文件并在那里编写以下代码。
DirectoryIndex index.php
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]