/**
  * Compiles the DSN string from a provided array, or from Config if none is given
  * @param array $dbinfo
  */
 public function __construct(array $dbinfo = null)
 {
     if (!$dbinfo) {
         $dbinfo = $this->_dbinfo = Config::get('dbinfo');
     }
     $type = $dbinfo['type'];
     $host = $dbinfo['host'];
     $port = $dbinfo['port'];
     $dbname = $dbinfo['dbname'];
     $this->_dsn = "{$type}:host={$host};port={$port};dbname={$dbname};";
 }
 public function Init()
 {
     // Sets some default values, these can be overriden
     if (!$this->_layout) {
         $this->_layout = Config::get('default_layout');
     }
     if ($this->_request->getFormat() != 'html') {
         $this->_layout = $this->_request->getFormat();
     }
     $this->_layout = View::factory('layout/' . $this->_layout);
     if (!$this->_pagetitle) {
         $this->_pagetitle = Config::get('default_pagetitle');
     }
     $this->pagetitle = $this->_pagetitle;
     $this->_response->setResponse($this->_layout);
 }
 /**
  * Parses and validates the request
  * @param <type> $string
  */
 public function route($string = null)
 {
     // parse the query string
     $string == null ? $string = $_SERVER['QUERY_STRING'] : null;
     // strip any GET data
     $pos = \strpos($string, '&');
     if ($pos) {
         $string = substr($string, 0, $pos);
     }
     $query = explode('/', $string);
     // remove empty entries, also removes '0' !
     $query = array_filter($query);
     // setting requested controller, using default from config if none requested
     $controller = isset($query[0]) ? $query[0] : Config::get('default_controller');
     $this->_request['controller'] = 'ezmvc\\controller\\actioncontroller\\' . $controller . 'Controller';
     // setting requested action, using defalt from config if none requested
     $action = isset($query[1]) ? $query[1] : Config::get('default_action');
     $this->_request['action'] = 'action' . ucfirst($action);
     // setting id
     $this->_request['id'] = isset($query[2]) ? $query[2] : null;
     // storing any additional parameters
     if (isset($query[3])) {
         $this->_request['params'] = array_splice($query, 3);
     }
     // validate the route
     $this->validateRoute();
 }
示例#4
0
 * @copyright  Copyright (c) 2011 Lars Kristian Dahl <http://www.krisd.com>
 * @license    http://www.apache.org/licenses/LICENSE-2.0
 */
namespace ezmvc;

use ezmvc\lib\Request;
use ezmvc\controller\FrontController;
use ezmvc\lib\AuthException;
use ezmvc\lib\Config;
// define the site path
$site_path = realpath(dirname(__FILE__));
define('__BASE_PATH', $site_path);
// set up the environment
include __BASE_PATH . '/bootstrapper.php';
//var_dump($_POST);
//var_dump($_GET);
// instantiate FrontController and route the request
try {
    FrontController::factory()->run();
    // catch any exceptions
} catch (AuthException $e) {
    $e->redirect(Config::get('loginpage'));
} catch (\ErrorException $e) {
    trigger_error($e->getMessage(), E_USER_ERROR);
    //    die('Fatal exception: ' . $e->getMessage());
    //    var_dump($e);
} catch (\Exception $e) {
    trigger_error($e->getMessage(), E_USER_ERROR);
    //    die('Exception caught: ' . $e->getMessage());
    //    var_dump($e);
}