public function __construct() { $this->db = Container::get("db"); }
/** * Here we NEED config options! */ public function __construct($config) { // Database connection $this->db = Container::get("db"); parent::__construct($config); }
*/ ini_set("html_errors", ini_get("display_errors")); // Set the default time zone date_default_timezone_set("Europe/Sofia"); // Composer include BASEPATH . "vendor/autoload.php"; // Setting path for auto config loader Config::$path = APPPATH . "config"; // PDO DB Handler Container::set("db", function () { $config = Config::get("db"); $db = new PDO($config["dsn"], $config["user"], $config["pass"]); // Set error handling to Exception $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Fetch return results as associative array $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); if (Config::get("db.dsn") == "sqlite::memory:") { $sql = file_get_contents(APPPATH . "Model/db.sql"); $db->exec($sql); } return $db; }); // return if we are coming form CLI (crontab jobs for example) if (php_sapi_name() == "cli") { return; } // Registering event listener for error 404, or when a route is not found Event::listen(array("404", "sugi.router.nomatch"), function () { Logger::debug("Page " . $_SERVER["REQUEST_URI"] . " Not Found"); header("HTTP/1.0 404 Not Found"); include APPPATH . "View/errors/404.html";