我是Codeigniter和使用Codeigniterv3的新手。我试图通过共享配置和模型等让自己的东西更容易维护。我的CodeIgniter有几个部分可以通过子域访问,但内部只是一个控制器文件夹。例如:
- api.domain.com-->域.com/api(适用于api(
- admin.domain.com-->domain.com/backend(适用于内部用户(
- dashboard.domain.com-->domain.com/frontend(适用于客户端用户(
- domain.com-->domain.com(用于登录页,但我不确定是否必须在文件夹中创建(
我需要你的帮助来解决我的问题:
- 如何设置我的Codeigniter以适合我的情况
- 对于登录页,最好的解决方案是创建文件夹还是不创建
这是一个在Codeigniter中管理多个应用程序的案例。有些方法可能与我下面提到的方法不同,其中可能包括/可能不包括虚拟主机配置。
假设您的domain.com有一个空的public_html文件夹(可能有一些默认文件夹和一个索引文件(
首先要做的是创建您想要的子域。api、admin和dashboard就是上面提到的。
创建子域将在public_html文件夹中创建子文件夹api、admin和dashboard。
上传codeigniter zip文件并将其提取到public_html文件夹中。现在public_html文件夹将包含以下文件夹:api、admin、dashboard、application、system、index.php等。
创建文件夹api,admin,仪表板,在应用程序文件夹中登录。将应用程序文件夹中已经存在的所有文件和文件夹复制到api、admin、dashboard和landing中。现在,应用程序文件夹将只有4个文件夹:api、admin、dashboard和landing。
将public_html文件夹中的index.php文件复制并粘贴到public_hhtml文件夹中的文件夹api、dashboard和admin中。
更改子域文件夹api、admin、dashboard中index.php文件中$system_path
和$application_folder
的值。下面是子域api的一个示例。在api/index.php文件的第90行附近可以看到这些代码行:
/*
*---------------------------------------------------------------
* SYSTEM DIRECTORY NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" directory.
* Set the path if it is not in the same directory as this file.
*/
// $system_path = 'system'; // change this line
$system_path = '../system';
/*
*---------------------------------------------------------------
* APPLICATION DIRECTORY NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* directory than the default one you can set its name here. The directory
* can also be renamed or relocated anywhere on your server. If you do,
* use an absolute (full) server path.
* For more info please see the user guide:
*
* https://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*/
// $application_folder = 'application'; // change this line
$application_folder = '../application/api';
同样适用于管理员:
// $system_path = 'system'; // change this line
$system_path = '../system';
// $application_folder = 'application'; // change this line
$application_folder = '../application/admin';
用于仪表板:
// $system_path = 'system'; // change this line
$system_path = '../system';
// $application_folder = 'application'; // change this line
$application_folder = '../application/dashboard';
着陆:
// $system_path = 'system'; // change this line
$system_path = '../system';
// $application_folder = 'application'; // change this line
$application_folder = '../application/landing';
现在您将能够访问:
- api.domain.com-->域.com/api(适用于api(
- admin.domain.com-->domain.com/admin(适用于内部用户(
- dashboard.domain.com-->domain.com/dashboard(适用于客户端用户(
- domain.com-->域名
如果您对这类项目使用slack会更好,这些项目可以被许多子域访问