【问题标题】:How to call controller in codeigniter from folder?如何从文件夹中调用codeigniter中的控制器?
【发布时间】:2016-03-04 13:00:50
【问题描述】:

我有一个网站

  • 前端:wordpress
  • 后端:codeigniter

Codeigniter 实例保存在名为 backend 的文件夹中。

搭建后端的测试环境。

  • 文件夹名称:团队
  • codeigniter 安装在: abc 文件夹

所以路径将是:

publichtml/团队/abc

现在尝试登录时出现404 未找到错误

谁能帮我看看脚本出了什么问题:

<script> 
function sendData() {
    var username = $("#username").val();
    var userpass = $("#userpass").val();

    $.post('https://example.com/team/abc/index.php/login/authenticateUserWeb',{ 'username': username, 'userpass': userpass }, function( data ) {

  alert(data);   
    if(data == 'success'){
      window.location = "https://example.com/team/abc/index.php/companyadmin/folders";

    }else if(data == 'successuser'){
      window.location = "https://example.com/team/abc/index.php/companyuser";  
    }else if(data == 'expired'){
      window.location = 'https://example.com/team/abc/index.php/companyadmin/selectPacakge';    

    }else{
            $("#user").html(data);
            //alert(data);
        }

});

    }

现在当我尝试登录时,在控制台日志中发现以下错误:

发布https://example.com/team/abc/index.php/login/authenticateUserWeb

301 永久移动

jquery-1.10.2.js (line 6) 获取https://example.com/team/abc/login/authenticateUserWeb

404 未找到

https://example.com/team/abc/login/authenticateUserWeb"

网络错误:404 未找到

【问题讨论】:

  • 不知道,但我注意到 index.php 已从 example.com/team/abc/index.php/login/authenticateUserWeb 中删除,并且 url 的更改类似于 GET example.com/team/abc/login/authenticateUserWeb
  • 这是我的配置文件:$config['base_url'] = "example.com/team/abc"; $config['index_page'] = 'index.php';$config['allow_get_array'] = TRUE; $config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd';
  • 我认为问题出在 HTACCESS
  • 你是对的@markin Bhatt。你能建议我如何设置 .htaccess cond 来访问后端文件夹吗?
  • 你好@MarmikBhatt 你能帮我解决这个问题吗?

标签: php ajax codeigniter


【解决方案1】:

如何在 codeigniter 中使用 wordpress 和其他项目添加 2 个项目

假设以下目录结构

www/
    .htaccess (wordpress htaccess)
    index.php (wordpress index.php and files)
www/backend/
    .htaccess (codeigniter htaccess)
    index.php (codeigniter htaccess)

对于 wordpress 的 HTACCESS 文件

//just add this line in wordpress htaccess
<Directory "backend/">
   Allow from all
</Directory>

对于 Codeigniter HTACCESS 文件

//add this lines in your codeigniter htaccess
RewriteEngine on
RewriteBase /backend/
...
RewriteRule ^(.*)$ /backend/index.php?/$1 [QSA,L]

这种类型每次都对我有用...

【讨论】:

    【解决方案2】:

    我还不能发表评论,但在我看来,你的 'index.php' 从 url 中消失了:

    https://example.com/team/abc/index.php/login/authenticateUserWeb
    

    可以在以下时间找到:

    https://example.com/team/abc/login/authenticateUserWeb
    

    不能(返回 404)。

    这两个url的区别在于最后一个没有/index.php/。

    您可以检查的一些步骤:

    • 您的 Codeigniter config.php 是否适应了您的测试后端的新位置? (base_url)。
    • 看来您在 url 中使用了 index.php,因此您没有使用重写 url 来在没有 index.php 的情况下工作。如果是这种情况,请确保 config.php 中的 'index_page' 设置正确(值:'index.php' 可能就足够了)并且不为空。

    【讨论】:

    • 这是我的配置文件:$config['base_url'] = "example.com/team/abc/";; $config['index_page'] = 'index.php';$config['allow_get_array'] = TRUE; $config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd';
    • 您的 Codeigniter 文件夹中是否有一个 .htaccess 文件可以用 'index.php' 重写 url 以从 url 中删除 'index.php'?如果是这样,请将 $config['index_page'] 中的值设为空字符串。
    • 不在 codeigniter 文件夹中,但我在 wordpress 中有 .htaccess 文件
    • 我无法测试它,但尝试在 RewriteBase / 之后添加 RewriteRule ^team/abc/.*$ - [L]
    猜你喜欢
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多