// Example on how to get a new db instance $newDdb = DB::getServerInstance('slave'); */ // // Register layout so they can referenced by name $bc->view->setLayouts(array('basic' => $path_layouts . 'basic.php', 'json' => $path_layouts . 'json.tpl.php', 'dialog' => $path_layouts . 'dialog.php')); $bc->view->setLayout('basic'); // // Register global values with view $bc->view->add('sitename', 'Basecoat'); // // Set path to template files $bc->view->setTemplatesPath($path_templates); // // Add a hook before output to process common page elements $bc->addBeforeRender(function () use($bc) { $content = new \Basecoat\View(); $content->processTemplate($bc->view->templates_path . 'common/header.php'); $content->processTemplate($bc->view->templates_path . 'common/footer.php'); $content->addToView($bc->view); $bc->view->add('requested_route', $bc->routing->requested_route); }); // // Define routes $routes = array('static' => array('file' => $path_routes . 'static.php', 'cacheable' => array('expires' => '20 minutes')), '/' => array('file' => $path_routes . 'index.php', 'template' => 'index.tpl.php'), 'login' => array('file' => $path_routes . 'login.php', 'template' => 'login.php', 'require_secure' => 1), 'logout' => array('file' => $path_routes . 'logout.php'), 'data' => array('file' => $path_routes . 'data.php', 'data_only' => 1), 'log' => array('file' => $path_routes . 'log_action.php', 'data_only' => 1), 'configuration' => array('file' => $path_routes . 'configuration.php', 'template' => 'configuration.tpl.php'), 'routes' => array('file' => $path_routes . 'routing.php', 'template' => 'routing.tpl.php'), 'content' => array('file' => $path_routes . 'content.php', 'template' => 'content.tpl.php'), 'database' => array('file' => $path_routes . 'database.php', 'template' => 'database.tpl.php', 'require_login' => false), 'messages' => array('file' => $path_routes . 'messages.php', 'template' => 'messaging.tpl.php'), 'examples' => array('file' => $path_routes . 'examples.php', 'template' => 'examples.tpl.php'), 'json' => array('file' => $path_routes . 'json.php', 'layout' => 'json'), 'login' => array('file' => $path_routes . 'login.php', 'template' => 'login.tpl.php'), 'hello' => array('function' => function () { exit('Hello World!'); }), 'undefined' => array('file' => $path_routes . '404.php', 'template' => '404.tpl.php', 'layout' => 'basic', 'data_only' => 1)); $bc->routing->setRoutes($routes); // // Process the request echo $bc->processRequest();
$basecoat->view->setLayouts(array('basic' => DIR_TPL . 'layouts/basic.php')); $basecoat->view->setLayout('basic'); // Set routes $routes = array('/' => array('file' => DIR_ROUTES . 'index.php', 'template' => 'index.tpl.php', 'methods' => array('POST', 'GET')), 'undefined' => array('file' => DIR_ROUTES . '404.php', 'template' => '404.tpl.php', 'cacheable' => array('expires' => '20 minutes'))); // Determine which routes to load if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'POST', 'PUT', 'DELETE'))) { include_once DIR_CONFIG . 'routes_' . strtolower($_SERVER['REQUEST_METHOD']) . '.php'; } $basecoat->routing->setRoutes($routes); $basecoat->routing->addBeforeEach(function () use($basecoat) { // Check if method matches if (isset($basecoat->routing->current['methods'])) { if (!in_array($_SERVER['REQUEST_METHOD'], $basecoat->routing->current['methods'])) { // Not a valid method for route, reset routes and run undefined $basecoat->routing->setRunRoutes(array('undefined'), true); } } }); //$basecoat->routing->set('use_pretty_urls', false); //$basecoat->routing->set('route_param', 'page'); // // Add a hook before output to process common page elements $basecoat->addBeforeRender(function () use($basecoat) { $content = new \Basecoat\View(); $content->processTemplate($basecoat->view->templates_path . 'common/header.php'); $content->processTemplate($basecoat->view->templates_path . 'common/footer.php'); $content->addToView($basecoat->view); }); // // Process the request echo $basecoat->processRequest();