/**
  * Construct the (base) controller. This happens when a real controller is constructed, like in
  * the constructor of IndexController when it says: parent::__construct();
  */
 protected function __construct()
 {
     // create a view object to be able to use it inside a controller, like $this->View
     $this->View = View::load();
     // create a app object to be able to use it inside a controller, like $this->App
     $this->App = App::load();
 }
Пример #2
0
<?php

/*
 * Load app
 */
use WebSupportDK\PHPMvcFramework\App;
// Start app
$app = App::load();
// Set absolute path
$app->set('__DIR__', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
define('BASE_PATH', $app->get('__DIR__'));
define('STORAGE_PATH', BASE_PATH . 'storage' . DIRECTORY_SEPARATOR);
// Set env constants (commenly used)
foreach (parse_ini_file(BASE_PATH . '.env.ini') as $key => $value) {
    define($key, $value);
}
// Set config depending on env
$app->set('config', require BASE_PATH . 'config/' . APP_ENV . '.php');
// Get or set something to/from app
function app($name, $value = null)
{
    global $app;
    if (!is_null($value)) {
        return $app->set($name, $value);
    }
    return $app->get($name);
}
// Set env varibale from constant or use default string
function env($constant, $string)
{
    return defined($constant) ? constant($constant) : $string;