mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
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)
|
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]);
|
$result = $this->_ci_load(['_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]);
|
||||||
|
|
||||||
$layout = config('layout');
|
$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]);
|
$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.
|
* @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, [
|
$vars = array_merge($params, [
|
||||||
'attributes' => $attributes
|
'attributes' => $attributes
|
||||||
]);
|
]);
|
||||||
|
|
||||||
extract($vars);
|
return $CI->load->view('components/' . $component, $vars, $return);
|
||||||
|
|
||||||
ob_start();
|
|
||||||
|
|
||||||
require APPPATH . 'views/components/' . $component . '.php';
|
|
||||||
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
if ($return)
|
|
||||||
{
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo $html;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue