Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi view rendering #2 #620

Merged
merged 18 commits into from
Feb 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions application/core/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ public function render($filename, $data = null)
require Config::get('PATH_VIEW') . '_templates/footer.php';
}

/**
* Similar to render, but accepts an array of separate views to render between the header and footer. Use like
* the following: $this->view->renderMulti(array('help/index', 'help/banner'));
* @param array $filenames Array of the paths of the to-be-rendered view, usually folder/file(.php) for each
* @param array $data Data to be used in the view
*/
public function renderMulti($filenames, $data = null)
{
if(!is_array($filenames)) {
self::render($filenames, $data);
return false;
}

if ($data) {
foreach ($data as $key => $value) {
$this->{$key} = $value;
}
}

require Config::get('PATH_VIEW') . '_templates/header.php';
foreach($filenames as $filename) {
require Config::get('PATH_VIEW') . $filename . '.php';
}
require Config::get('PATH_VIEW') . '_templates/footer.php';
}

/**
* Same like render(), but does not include header and footer
* @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
Expand Down