base_path = $base_path; } /** * Render a view file. This will be used to render a whole page. * If a layout is defined, then we will render layout + view. * * @param string $view The name of the view file to render. * @param array $params An optional array of parameters to pass to the view file. * * @return string */ public function render( $view, $params = array() ) { $view_file = $this->base_path . DIRECTORY_SEPARATOR . $view . '.php'; if ( is_file( $view_file ) ) { $content = $this->render_php_file( $view_file, $params ); return $content; } return ''; } /** * Renders a PHP file and returns its output. * * @param string $file The path to the PHP file to render. * @param array $params An optional array of parameters to pass to the PHP file. * * @return string The output of the rendered PHP file. */ private function render_php_file( $file, $params = array() ) { ob_start(); ob_implicit_flush( false ); foreach ( $params as $key => $value ) { $$key = $value; } require $file; return ob_get_clean(); } }