【问题标题】:Codeigniter Controller is not workingCodeigniter 控制器不工作
【发布时间】:2017-05-29 06:49:01
【问题描述】:

我是 codeigniter 的新手,有点困惑我的调节器没有拾取我的控制器,我的控制器 practice.php 和代码是:

class Practice extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    function foo()
    {
        echo 'Hello world';
    }
    function index()
    {
        echo 'Hello index';
    }
}

我正在尝试像 Localhost/foldername/practice/foo 一样加载它。它假设工作为什么不呢?

谢谢。

注意:实践也是我的默认控制器,没有控制器名称索引功能就像localhost/foldername/一样会显示索引功能结果。

【问题讨论】:

  • 为什么需要文件夹名称?
  • pr 是 codeigniter 所在的文件夹,所以我当然需要地址栏中的这个文件夹名称。
  • localhost/foldername/index.php/practice/foo 并将 practice.php 文件重命名为 Practice.php
  • 如果你使用 .htaccess 文件,那么你可以避免来自 url 的 index.php
  • 控制器文件先后后大?

标签: php codeigniter class


【解决方案1】:

CodeIgniter 说:

默认情况下,index.php 文件将包含在您的 URL 中:

example.com/index.php/news/article/my_article

尝试使用这个访问它

localhost/foldername/index.php/practice/foo

如果你想在没有 index.php 的情况下访问它,你应该在你的根目录中创建一个 .htaccess 文件并放置以下代码:

重写引擎开启

RewriteBase /foldername/
# If your project is in server root then should be: RewriteBase /
# If your project is in folder then it should be: RewriteBase /foldername/

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

CodeIgniter URLs

【讨论】:

    猜你喜欢
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2019-03-21
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多