-
Notifications
You must be signed in to change notification settings - Fork 5
Env File
Hossein Pira edited this page Aug 25, 2023
·
3 revisions
In API-Monster you are not limited.
You can create your config file with any name. Such as: .env, .AppConfig and ...
It is enough to call it in a controller or function as follows:
<?php
namespace Monster\App\Controllers;
use Monster\App\Models\Env;
class AppController
{
public function index()
{
$env = new Env(".env");
echo $env->get("APP_NAME");
}
}
Take your .env file as an example. Create your own file in the root of the project and read the desired values in it.
Note: Do not delete the default .env file in API-Monster, because it contains debug. You are able to create unlimited config files or config values.
APP_NAME="API-Monster"
APP_DEBUG=true
You can: Enter values with or without "". But note that for values with spaces, be sure to put in "". for example:
USER_ID=123456
USER_NAME="Hossein Pira"
USER_URL=http://localhost:8000/user/123456
<?php
namespace Monster\App\Controllers;
use Monster\App\Models\Env;
class AppController
{
public function index()
{
$env = new Env(".env");
$db = new Env('.db');
echo $env->get("APP_NAME") . '<br />';
echo $env->get("APP_URL") . '<br />';
echo $db->get("HOST");
}
}
Space in the config file has no meaning and is allowed.
APP_URL = "https://google.com"
- 1 - Installation
- 2 - Routing And Database
- 3 - HTTP Request
- 4 - CORS
- 5 - Env File
- 6 - Views
- 7 - Language
- 8 - SPA Without API
- 9 - Data Validation
- 1 - Installation
- 2 - Routing And Database
- 3 - HTTP Request
- 4 - CORS
- 5 - Env File
- 6 - Views
- 7 - Language
- 8 - SPA Without API
- 9 - Data Validation