forked from mirrors/easyappointments
Allow multiple renders with the loader class during the rendering of a layout page
This commit is contained in:
parent
35f9a6eb1c
commit
532ee4fabc
2 changed files with 13 additions and 23 deletions
|
@ -51,11 +51,15 @@ class EA_Loader extends CI_Loader {
|
|||
*/
|
||||
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]);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue