-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
45 lines (37 loc) · 1.4 KB
/
index.php
File metadata and controls
45 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// Set the full path to the docroot
define('DOCROOT', realpath(dirname(__FILE__)).'/');
// The directory in which your application specific resources are located.
define('APPPATH', DOCROOT.'app/');
define('LIBPATH', DOCROOT.'lib/');
// Enable the auto-loader.
require_once(DOCROOT.'autoload.php');
//spl_autoload_register(array('Loader', 'autoload'));
// Bootstrap the application
require_once(APPPATH.'bootstrap.php');
// Parse the uri and execute the request
$uri = explode('/', ( ! empty($_GET['candy_uri'])) ? $_GET['candy_uri'] : DEFAULT_CONTROLLER);
$route = array(
'controller' => $uri[0],
'method' => ( ! empty($uri[1])) ? 'page_'.$uri[1] : 'page_index',
'param' => isset($uri[2]) ? $uri[2] : NULL
);
try
{
$controller = 'Controller_'.strtolower(ucfirst($route['controller']));
$controller = new $controller;
// Throw page not found exception if method is not callable
if ( ! is_callable(array($controller, $route['method'])) )
{
throw new Candy_Exception('The requested '.$route['method'].' could not be found in '.$route['controller'].' controller', 404);
}
$controller->{$route['method']}($route['param']);
echo $controller
->getResponse();
}
catch (Candy_Exception $ex)
{
$errorView = Candy_View::factory( 'error', array('code' => $ex->getCode()) );
echo Candy_View::factory('layout')
->set('content', $errorView);
}