无法浏览到编码器自定义控制器


unable to browse to codeigniter custom controller

我有codeigniter 3的问题,我使用netbeans作为我的IDE和wampserver。我能够成功地浏览'localhost/ci_test/' (ci_test是项目/网站的名称),它为我提供了默认的welcome.php控制器,然而,我在CI控制器文件夹内尝试了第二个控制器,名为"Test.php",内容如下:

<?php 
   class Test extends CI_Controller {  
      public function index() { 
         echo "This is default function."; 
      } 
      public function hello() { 
         echo "This is hello function."; 
      } 
   } 
?>

,然后当我试图浏览到控制器:与以下url:http://localhost/ci_test/index.php/test它为我提供了welcome.php(这不是我想要的),

然后我尝试了这个url:http://localhost/ci_test/test.php

,我得到了一个回应:

Not Found
The requested URL /ci_test/test.php was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

我不明白我在这里错过了什么…

注意:我没有更改codeigniter提供的。haccess文件,并将它们保留原样(可能存在问题)。

我只在CI中更改了以下内容:

应用程序/config/config . php:

$config['base_url'] = 'http://localhost/ci_test/';
$config['index_page'] = ''
$config['uri_protocol'] = 'PATH_INFO';

我希望有人能帮助这里:)

编辑:我已经阅读了前4个答案,它仍然不起作用

EDIT2:所以在我决定放弃之后,我注意到我的apache服务器没有"mod_rewrite",所以我把它打开了再次尝试相同的项目,它仍然没有工作,然后我决定从头开始创建一个新项目,并使用CI,我添加了新的控制器,现在一切都运行良好。这是哈哈…非常感谢那些试图帮助我的人

你需要直接访问测试控制器,然后你需要在项目根目录中添加。htaccess文件。下面是.htaccess文件,用于避免在codeigniter

中使用index.php
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

如果你把这个。htaccess文件添加到根目录,你的问题就解决了。

也不需要在你的url (http://localhost/ci_test/test.php)中添加扩展,这是错误的

http://localhost/ci_test/test

这足以加载你的控制器

欢迎控制器

<?php
class Welcome extends MY_Controller 
{
    public function index()
    {
       $this->load->view('welcome');
    }
}

欢迎视图

<a href="<?php echo base_url('test'); ?>">Test Page</a>
测试控制器

<?php
class Test extends MY_Controller 
{
    public function index()
    {
       $this->load->view('test');
    }
}

测试视图

<h1>Test Page</h1>

视图必须命名为test.php和welcome.php,并放在views文件夹中。

让我们知道你进展如何。


查看config文件夹

中的routes.php文件

Change $route['default_controller'] = 'welcome';

$route['default_controller'] = 'test';

看看是否可以

如果出现找不到页面的错误请查看地址栏,如果是这样

http://localhost/ci_test/test

试试改成这个

http://localhost/index.php/ci_test/test

开箱即用,codeigniter使用url。com/controller/method .

您已经创建了一个名为Test.php的测试控制器。要访问它,您可以使用…

http://localhost/ci_test/test

这是一个仓促的回答…如果您正在使用WAMPServer,请检查它是否没有在httpd文件或vhosts文件中设置MultiViews(如果您正在使用该文件)