Exemple #1
0
	function route ($root, $route) {
		
		// Get the root path from where admin is running
		self::$root = url(Frix::config('WEB_ROOT'), $root, '/');
		self::$route = $route;
		
		// Put the root path into the URL
		self::$context['root'] = self::$root;
		
		// TODO: create some type of decorator to require authentication on views
		// to avoid this kind of hack manually checking the route here...
		// Forgot password route?
		if (str_replace('/', '', $route) == 'forgot') {
			return $this->forgot();
		}
		
		// Load Auth app
		$auth_app = Frix::app('auth');
		// Check if user is authorized
		if (!$auth_app->get_user()) {
			return $this->login();
		}
		
		// Load Admin app
		$this->admin = Frix::app('admin');
		
		// List all the installed apps
		foreach (Frix::config('APPS') as $name => $path) {
			
			// Create an App instance
			$app = Frix::app($name);
			
			// Try to import options
			try {
				import(join_path(array($app->path, 'admin.php')));
			}
			// Go to next app on failure
			catch (ImportException $e) {
				continue;
			}
			
			// Any registered model?
			if (array_key_exists($name, $this->admin->registry)) {
				// Inject an URL attribute in the app
				$app->admin_url = url(self::$root, $name);
				self::$context['apps'][$name] = $app;
			}
			
		}
		
		// Initialize breadcrumbs
		self::$context['breadcrumbs'] = array();
		
		// Load route config
		// TODO: make router allow URL 'inclusions' instead of creating multiple routers
		require_once(join_path(array($this->admin->path, 'routes.php')));
		
		// Use the Router to map the command string to a view
		// TODO: try to trick Router to jump the application resolval
		// and use this instance of the views
		$router = new Router($routes, $route);
		$router->start();
		
		// Let the template know what view is running
		self::$context['view_name'] = $router->view_name;
		
	}