Php 如何给出完整的控制器&x27;codeigniter中的s路径

Php 如何给出完整的控制器&x27;codeigniter中的s路径,php,javascript,jquery,codeigniter,Php,Javascript,Jquery,Codeigniter,我有一个javascript变量,如下所示,运行良好 var url = http://example.com/directory_name/ 上面的链接返回json数据,稍后我将使用javascript显示这些数据。 但我想要的是给出一个控制器的完整路径,然后给出函数名,如下所示 http://example.com/directory_name/api/v1/ //whereas api is controller's name and v1 function inside this co

我有一个javascript变量,如下所示,运行良好

var url = http://example.com/directory_name/
上面的链接返回json数据,稍后我将使用javascript显示这些数据。 但我想要的是给出一个控制器的完整路径,然后给出函数名,如下所示

http://example.com/directory_name/api/v1/ //whereas api is controller's name and v1 function inside this controller
我怎样才能做到这一点

更新

这是我的控制器代码

class Api extends CI_Controller {
public function index() {
    //$this->load->view('api');
    $this->v1('api');
}

public function v1 () {
    //$this->load->view('api');
    echo site_url();
    $arr = array(
      array(
        'id' => 15642,
        'title' => 'title one',
        'description' => 'this is description for title one'
      ),
      array(
        'id' => 15643,
        'title' => 'title two',
        'description' => 'this is description for title two'
      ),
      array(
        'id' => 15644,
        'title' => 'title Three',
        'description' => 'this is description for title Three. this is description for title Three. this is description for title Three.'
      )
    );

    echo json_encode($arr);
}
}
更新2

这是JS

init: function (jokesContainer) {
            container = container;
            url       = 'http://example.com/directory/api/v1';    
            Get.get(url, container);
        }
更新3

.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase chrome_web_apps

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

RewriteCond %{REQUEST_URI} ^application.*
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>

重新启动发动机
重写基本chrome\u web\u应用程序
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$index.php?/$1[L]
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$index.php?/$1[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
ErrorDocument 404/index.php

1st。创建重写规则:将此代码设置到主文件夹的.htaccess文件中,其中是app/sys文件夹中的main index.php

这一点很重要,这样你的链接才能以其他方式工作,你只能加载主页

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
*请注意,您的服务器必须接受HTACCESS文件才能正常工作

第二。从CI URL中删除index.php。 在

查找并设置为空

$config['index_page'] = '';
三,。要生成正确的URL,请使用该CI php函数

site_url("api/v1");
它需要url帮助程序

您想在php文件中写入完整的站点/控制器/操作路径吗?我想在javascript url变量中给出完整路径。所以/directory/api/v1不起作用?您是否设置了路由器?您是否在路由器上设置了路由?(复制它)这就是我在路由中的所有内容
$route['default\u controller']=“api”$路由['404_覆盖']=''我不想在javascript中使用任何php代码。因为我将该链接公开,所以我只想让用户复制整个链接并使用它。要向用户显示它,您必须生成它。。您可以通过PHP代码实现这一点。@al0neevenings站点\u url。。我在回答时加上的。我将在哪里添加site_url()方法?在控制器中或在哪里?当我没有你的代码时如何告诉你。。如果需要,请将其添加到视图文件中。。
site_url("api/v1");