diff --git a/application/core/EA_Loader.php b/application/core/EA_Loader.php index a6734da8..abbfe8b5 100644 --- a/application/core/EA_Loader.php +++ b/application/core/EA_Loader.php @@ -41,21 +41,25 @@ */ class EA_Loader extends CI_Loader { /** - * Override the original view loader method so that layouts are also supported. - * + * Override the original view loader method so that layouts are also supported. + * * @param string $view View filename. * @param array $vars An associative array of data to be extracted for use in the view. * @param bool $return Whether to return the view output or leave it to the Output class. - * + * * @return object|string */ public function view($view, $vars = [], $return = FALSE) { + $layout = config('layout'); + + $is_layout_page = empty($layout); // This is a layout page if "layout" was undefined before the page got rendered. + $result = $this->_ci_load(['_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]); $layout = config('layout'); - if ($layout) + if ($layout && $is_layout_page) { $result = $this->_ci_load(['_ci_view' => $layout['filename'], '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]); } diff --git a/application/helpers/html_helper.php b/application/helpers/html_helper.php index 3bbf706a..db2e4069 100644 --- a/application/helpers/html_helper.php +++ b/application/helpers/html_helper.php @@ -32,30 +32,16 @@ if ( ! function_exists('component')) * * @return string Return the HTML if the $return argument is TRUE or NULL. */ - function component(string $component, string $attributes = '', array $params = [], bool $return = FALSE): ?string + function component(string $component, string $attributes = '', array $params = [], bool $return = FALSE) { + /** @var EA_Controller $CI */ + $CI = get_instance(); + $vars = array_merge($params, [ 'attributes' => $attributes ]); - extract($vars); - - ob_start(); - - require APPPATH . 'views/components/' . $component . '.php'; - - $html = ob_get_clean(); - - if ($return) - { - return $html; - } - else - { - echo $html; - - return NULL; - } + return $CI->load->view('components/' . $component, $vars, $return); } }