Skip to content

Env File

Hossein Pira edited this page Aug 25, 2023 · 3 revisions

Env

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.

Example

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

A larger example:

<?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"
Clone this wiki locally