Reimplemented Kohana 2.3's View::set_global() with array support.

Allows for cleaner code and fewer function calls.
This commit is contained in:
Joe7
2011-01-02 18:59:23 +01:00
committed by Bharat Mediratta
parent e6a5f39b91
commit cfaa62370e
4 changed files with 35 additions and 26 deletions

View File

@@ -61,14 +61,15 @@ class Albums_Controller extends Items_Controller {
}
$template = new Theme_View("page.html", "collection", "album");
$template->set_global("page", $page);
$template->set_global("page_title", null);
$template->set_global("max_pages", $max_pages);
$template->set_global("page_size", $page_size);
$template->set_global("item", $album);
$template->set_global("children", $album->viewable()->children($page_size, $offset));
$template->set_global("children_count", $children_count);
$template->set_global("parents", $album->parents()->as_array()); // view calls empty() on this
$template->set_global(array("page" => $page,
"page_title" => null,
"max_pages" => $max_pages,
"page_size" => $page_size,
"item" => $album,
"children" => $album->viewable()->children($page_size, $offset),
"children_count" => $children_count,
"parents" => $album->parents()->as_array()));
// view calls empty() on this
$template->content = new View("album.html");
$album->increment_view_count();

View File

@@ -38,14 +38,15 @@ class Movies_Controller extends Items_Controller {
}
$template = new Theme_View("page.html", "item", "movie");
$template->set_global("item", $movie);
$template->set_global("children", array());
$template->set_global("children_count", 0);
$template->set_global("parents", $movie->parents()->as_array());
$template->set_global("next_item", $next_item);
$template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where));
$template->set_global("position", $position);
$template->set_global(array("item" => $movie,
"children" => array(),
"children_count" => 0,
"parents" => $movie->parents()->as_array(),
"next_item" => $next_item,
"previous_item" => $previous_item,
"sibling_count"
=> $movie->parent()->viewable()->children_count($where),
"position" => $position));
$template->content = new View("movie.html");

View File

@@ -38,14 +38,15 @@ class Photos_Controller extends Items_Controller {
}
$template = new Theme_View("page.html", "item", "photo");
$template->set_global("item", $photo);
$template->set_global("children", array());
$template->set_global("children_count", 0);
$template->set_global("parents", $photo->parents()->as_array());
$template->set_global("next_item", $next_item);
$template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $photo->parent()->viewable()->children_count($where));
$template->set_global("position", $position);
$template->set_global(array("item" => $photo,
"children" => array(),
"children_count" => 0,
"parents" => $photo->parents()->as_array(),
"next_item" => $next_item,
"previous_item" => $previous_item,
"sibling_count"
=> $photo->parent()->viewable()->children_count($where),
"position" => $position));
$template->content = new View("photo.html");

View File

@@ -23,8 +23,14 @@ class View extends View_Core {
/**
* Reimplement Kohana 2.3's View::set_global() functionality.
*/
public function set_global($key, $value) {
View::$global_data[$key] = $value;
public function set_global($key, $value = NULL) {
if (is_array($key)) {
foreach ($key as $key2 => $value) {
View::$global_data[$key2] = $value;
}
} else {
View::$global_data[$key] = $value;
}
}
public function is_set($key=null) {