public static function start() { # load config $config = (include __DIR__ . '/settings.php'); self::$config = $config; self::loadClasses(); # bind array $config ke class Connection Connection::setConfig(self::$config['db']); # make a route $router = new Route(self::$config); # match the current request $match = $router->getRoute()->match(); if ($match && is_callable($match['target'])) { call_user_func_array($match['target'], $match['params']); } else { # no route was matched header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); echo "<h3>No Route was matched with</h3>"; echo "<table>"; echo "<tr>"; echo "<th>Method</th>"; echo "<th>Route</th>"; echo "</tr>"; // echo "<td>Controller</td>"; foreach ($router->getRoute()->getRoutes() as $route) { print "<tr>"; print "<td> {$route['0']} </td>"; print "<td> {$route['1']} </td>"; print "<tr>"; } echo "</table>"; } }
public function start() { # start PHP session session_start(); $this->loadClasses(); # FIXME # require('Ngaji/Routing/Router.php'); # bind array $config ke class Connection Connection::setConfig($this->config['db']); # make a route $router = new Route($this->config); # TODO use pregex to handle client request # router2 // $router2 = new Router2($this->config); # match the current request $match = $router->getRoute()->match(); if ($match && is_callable($match['target'])) { call_user_func_array($match['target'], $match['params']); } else { # no route was matched header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); echo "<h3>No Route was matched with</h3>"; echo "<table>"; echo "<tr>"; echo "<th>Method</th>"; echo "<th>Route</th>"; echo "</tr>"; // echo "<td>Controller</td>"; foreach ($router->getRoute()->getRoutes() as $route) { print "<tr>"; print "<td> {$route['0']} </td>"; print "<td> {$route['1']} </td>"; print "<tr>"; } echo "</table>"; } }
/** * Make the instance of the object */ public function __construct() { $this->pdo = Connection::connect(); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }