【问题标题】:can't call the second function in controller codeigniter无法调用控制器 codeigniter 中的第二个函数
【发布时间】:2012-04-14 22:34:29
【问题描述】:

我是 codeigniter 的新手,我有问题

我使用我的 OS X Lion,我使用 .htaccess 我可以直接调用 localhost/site_folder/ 它就像魅力一样工作,但我的控制器中有第二个函数但我不能像这样直接调用该函数 localhost/ site_folder/function2

这里是我的控制器

class My_site extends CI_Controller {
function __construct() {
  parent::__construct();
  }
function index() {
  --some script--
  }
function function2() {
  --some script--
  }
}

它说找不到url,为什么?

谢谢

【问题讨论】:

  • 你能把路线代码放在这里吗? (config/routes.php)
  • 如果 My_Site 不是您的默认控制器,我想您需要通过 http://localhost/site_folder/my_site/function2 调用它
  • @safarov 这是我的config/routes $route['default_controller'] = "myshop"@Shiplu 我已经像你说的那样尝试了,但没有结果..

标签: php .htaccess codeigniter controller clean-urls


【解决方案1】:

默认路由方案是example.com/class/function/id/ Doc

如果site_folder 是您安装codeigniter 的文件夹,您的function2 的url 将是,

http://localhost/site_folder/my_site/function2

【讨论】:

  • 我仍然无法访问.. 这里是我的 .htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|robots\.txt|css) RewriteRule ^(.*)$ index.php/$1 [L] 对吗?
【解决方案2】:

我在这个论坛http://ellislab.com/forums/viewthread/210578/找到了解决方案

【讨论】:

    【解决方案3】:
      It may be the issue please Check the uri protocol in the config file that should be AUTO.
    
      Config/config.php ===> $config['uri_protocol']    = 'AUTO';
    

    【讨论】:

      【解决方案4】:

      根据Mushicodeigniter 自动将 index.php 添加到您在 config.php 文件中指定的“localhost/site_folder/”(第 38 行)。所以要调用这个函数,你必须去'localhost/site_folder/index.php/function2'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-02
        • 1970-01-01
        • 2020-02-22
        • 1970-01-01
        • 2017-12-10
        • 2017-07-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多