Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from lornajane/admin-template-labels

Template Labels
  • Loading branch information...
commit c9b977b7a8e4e3b47a29dd7df9d77feb9d87320b 2 parents 4547fed + d3ac94e
@spf13 authored
View
15 app/routes/articles.php
@@ -7,25 +7,30 @@ class articles_route {
public function page_init() {
auth::check();
- $s = Slim::getInstance();
- $s->view()->setData('section', 'articles');
- $s->view()->setData('label', 'article');
- $s->view()->setData('prefix', $this->prefix);
}
public function post_init() {
auth::check();
}
+ public static function set_view_data() {
+ $s = Slim::getInstance();
+ $s->view()->setData('section', 'Articles');
+ $s->view()->setData('label', 'Article');
+ $s->view()->setData('prefix', 'article');
+ }
+
function __construct() {
$s = Slim::getInstance();
$prefix = $this->prefix;
$s->get($this->base, $this->page_init(), function () use ($s) {
+ articles_route::set_view_data();
return $s->render('articles/list.tpl', array('action_name' => 'List', 'articles' => $s->db->articles->find()));
})->name($prefix);
$s->get($this->base . 'create', $this->page_init(), function () use ($s) {
+ articles_route::set_view_data();
foreach($s->db->users->find() as $author) {
$authors[$author['_id']] = $author['display_name'];
}
@@ -55,6 +60,7 @@ function __construct() {
})->name($prefix . '_create_post');
$s->get($this->base . '(:_id)/edit', $this->page_init(), function ($_id) use ($s,$prefix) {
+ articles_route::set_view_data();
foreach($s->db->users->find() as $author) {
$authors[$author['_id']] = $author['display_name'];
}
@@ -74,6 +80,7 @@ function __construct() {
})->name($prefix . '_delete');
$s->get($this->base . '(:_id)', $this->page_init(), function ($_id) {
+ articles_route::set_view_data();
echo "Hello, $_id!";
})->name($prefix . '_view');
}
View
2  app/routes/post.php
@@ -14,6 +14,7 @@ function __construct() {
$s->get($this->base . "(:slug)", $this->page_init(), function ($slug) use ($s) {
return $s->render('posts/view.tpl', array(
'action_name' => 'List',
+ 'label' => 'Post',
'post' => $s->db->articles->findone(array('slug' => $slug))
));
})->name($prefix);
@@ -21,6 +22,7 @@ function __construct() {
$s->get("/", $this->page_init(), function () use ($s) {
return $s->render('posts/home.tpl', array(
'action_name' => 'List',
+ 'label' => 'Posts',
'posts' => $s->db->articles->find()
));
})->name('home');
View
1  app/routes/tag.php
@@ -14,6 +14,7 @@ function __construct() {
$s->get($this->base . "(:tag)", $this->page_init(), function ($tag) use ($s) {
return $s->render('posts/tag.tpl', array(
'tag' => $tag,
+ 'label' => 'Posts by Tag',
'action_name' => 'List',
'posts' => $s->db->articles->find(array('tags' => $tag))));
})->name($prefix);
View
19 app/routes/users.php
@@ -7,25 +7,30 @@ class users_route {
public function page_init() {
auth::check();
- $s = Slim::getInstance();
- $s->view()->setData('section', 'Users');
- $s->view()->setData('label', 'User');
- $s->view()->setData('prefix', $this->prefix);
}
public function post_init() {
auth::check();
}
+ public static function set_view_data() {
+ $s = Slim::getInstance();
+ $s->view()->setData('section', 'Users');
+ $s->view()->setData('label', 'User');
+ $s->view()->setData('prefix', 'user');
+ }
+
function __construct() {
$s = Slim::getInstance();
$prefix = $this->prefix;
- $s->get($this->base, $this->page_init(), function () use ($s) {
+ $s->get($this->base, $this->page_init(), function () use ($s, $prefix) {
+ users_route::set_view_data();
return $s->render('users/list.tpl', array('action_name' => 'List', 'users' => $s->db->users->find()));
})->name($prefix);
- $s->get($this->base . 'create', $this->page_init(), function () use ($s) {
+ $s->get($this->base . 'create', $this->page_init(), function () use ($s, $prefix) {
+ users_route::set_view_data();
return $s->render('users/edit.tpl', array('action_name' => 'Create', 'user' => (array) new User()));
})->name($prefix . '_create');
@@ -38,6 +43,7 @@ function __construct() {
})->name($prefix . '_create_post');
$s->get($this->base . '(:_id)/edit', $this->page_init(), function ($_id) use ($s,$prefix) {
+ users_route::set_view_data();
$user = $s->db->users->findOne(array( '_id' => $_id));
if (empty($user)) { $s->notFound(); }
return $s->render('users/edit.tpl', array( 'form_action' => $s->urlFor($prefix . "_create"), 'action_name' => 'Edit', 'user' => $user));
@@ -49,6 +55,7 @@ function __construct() {
})->name($prefix . '_delete');
$s->get($this->base . '(:_id)', $this->page_init(), function ($_id) {
+ users_route::set_view_data();
echo "Hello, $_id!";
})->name($prefix . '_view');
}
Please sign in to comment.
Something went wrong with that request. Please try again.