/** * Render data * * @param $view * @param array $data * @return string */ public static function renderIt($view, array $data) { self::$_layout = $view; self::$_data = !empty($data) ? $data : array(); $router = DIContainer::build('router'); $app = DIContainer::build('app'); $config = DIContainer::build('config'); $funCurRoute = $router->findRoute(); $funGetRoute = function ($route_name, $params = null) use($router) { return $router->generateRoute($route_name, $params); }; $funDoAction = function ($class_name, $action, $params) use($app) { $response = $app->runControllerAction($class_name, $action, $params); if (is_object($response)) { $response->send(); } }; $funGetImg = function ($img) { $default_img = '/img/phone.png'; return !empty($img) && getimagesize($img) ? $img : $default_img; }; $data = array_merge($data, array('config' => $config, 'getRoute' => $funGetRoute, 'include' => $funDoAction, 'route' => $funCurRoute, 'getImg' => $funGetImg, 'isAjax' => self::isAjax())); ob_start(); extract(self::$_data); extract($data); include self::$_layout; $result = ob_get_clean(); return $result; }