Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有API的CodeIgniter站点。相同的代码基但不同的控制器_Php_Codeigniter_Model View Controller - Fatal编程技术网

Php 带有API的CodeIgniter站点。相同的代码基但不同的控制器

Php 带有API的CodeIgniter站点。相同的代码基但不同的控制器,php,codeigniter,model-view-controller,Php,Codeigniter,Model View Controller,我正试图找到一种方法,使CodeIgniter站点具有前端和api。前端部分将是http://example.com及其APIhttp://api.example.com 但是,我在分离控制器时遇到问题。因为除了控制器之外,两个站点共享几乎相同的数据,所以我不想维护两个不同的应用程序。目前,我已设置了以下各项: backend └─ server └─ application └─ controllers ├─ api <- For http://api

我正试图找到一种方法,使CodeIgniter站点具有前端和api。前端部分将是
http://example.com
及其API
http://api.example.com

但是,我在分离控制器时遇到问题。因为除了控制器之外,两个站点共享几乎相同的数据,所以我不想维护两个不同的应用程序。目前,我已设置了以下各项:

backend
└─ server
   └─ application
      └─ controllers
         ├─ api <- For http://api.example.com
         └─ www <- For http://example.com

frontend
├─ .htaccess
└─ index.php <- Where http://example.com points to

api
├─ .htaccess
└─ index.php <- Where http://api.example.com points to

API
常量在
/API/index.php
中设置为true,在
/frontend/index.php

中设置为false。您可以显示为路由设置的内容吗?@mim。我主要只是做了些实验,但没有什么感觉足够灵活。有点像。你是如何签入routes.php的?你是如何签入routes.php中的api的?你是在问
if(api)在哪里{
被定义了吗?它在
/api/index.php
中设置为true,在
/frontend/index.php
中设置为false,你能显示你为路由设置了什么吗?@mim.我主要是做实验,但感觉不够灵活。有点像。你是如何签入路由的。来自api的php请求正在路由中签入api.php?@umefarooq是什么如果(API){定义在哪里,您会问吗?在
/API/index.php
中设置为true,在
/frontend/index.php中设置为false
if(API) {
    $route['default_controller'] = 'apihome';
    $route['(:any)/(:any)'] = 'api/$1/$2';
    $route['(:any)'] = 'api/$1';
    $route['foo/(:num)'] = 'api/foo/$1';
} else {
    $route['default_controller'] = 'wwwhome';
    $route['(:any)'] = 'api/$1';
}