Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: mogria/void.php
base: a9336314a8
...
head fork: mogria/void.php
compare: 4be2e5d545
  • 14 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
47 Controllers/CategoriesController.php
View
@@ -0,0 +1,47 @@
+<?php
+
+namespace Void;
+use \Exception;
+
+class CategoriesController extends ApplicationController {
+
+ public function action_index() {
+ $this->categories = Category::all();
+ }
+
+ public function action_new() {
+ $this->category = new Category($_POST);
+ if($this->category->save()) {
+ Router::redirect('categories', 'show', Array($this->category->id));
+ }
+ }
+
+ public function action_show($id = null) {
+ try {
+ $this->category = Category::find($id);
+ } catch(Exception $ex) {
+ header("404 Not Found");
+ $this->category = null;
+ }
+ }
+
+ public function action_edit($id = null) {
+ try {
+ $this->category = Category::find($id);
+ if($this->category->update_attributes($_POST)) {
+ throw Exception();
+ }
+ } catch(Exception $ex) {
+ Router::redirect('category', 'show', Array($id));
+ }
+ }
+
+ public function action_delete($id = null) {
+ try {
+ Category::find($id)->delete();
+ Flash::success('The category was successfully deleted');
+ Router::redirect('categories');
+ } catch(Exception $ex) {
+ }
+ }
+}
28 Controllers/PostsController.php
View
@@ -11,9 +11,6 @@ public function action_index() {
public function action_show($id = null) {
try {
- if($id === null) {
- throw new \Exception();
- }
$this->post = Post::find((int)$id);
} catch(Exception $ex) {
header("404 Not Found");
@@ -21,12 +18,33 @@ public function action_show($id = null) {
}
}
public function action_new() {
+ $this->post = new Post($_POST);
+ // @todo: change this when we have an authentification system
+ $this->post->user_id = 1;
+ if($this->post->save()) {
+ Router::redirect('posts', 'show', Array($this->post->id));
+ }
}
public function action_create() {
}
- public function action_edit() {
+ public function action_edit($id = null) {
+ try {
+ $this->post = Post::find($id);
+ if($this->post->update_attributes($_POST)) {
+ throw Exception();
+ }
+ } catch(Exception $ex) {
+ Router::redirect('posts', 'show', Array($id));
+ }
}
- public function action_delete() {
+ public function action_delete($id = null) {
+ try {
+ Post::find($id)->delete();
+ Flash::success('The post was sucessfully deleted');
+ Router::redirect('posts');
+ } catch(Exception $ex) {
+ Router::redirect('posts', 'show', Array($id));
+ }
}
}
6 Helpers/CategoriesHelper.php
View
@@ -0,0 +1,6 @@
+<?php
+
+namespace Void;
+
+class CategoriesHelper extends ApplicationHelper {
+}
9 Models/Category.php
View
@@ -17,6 +17,7 @@
namespace Void;
class Category extends \ActiveRecord\Model {
+ static $attr_accessible = Array('name', 'parent_category_id');
static $validates_presence_of = Array(
Array('name')
);
@@ -24,4 +25,12 @@ class Category extends \ActiveRecord\Model {
Array('name', 'maximum' => 255),
Array('parent_category_id', 'maximum' => 11)
);
+
+ static $belongs_to = Array(
+ //Array('category_assign')
+ );
+ static $has_many = Array(
+ Array('category_assigns'),
+ Array('posts', 'through' => 'category_assign')
+ );
}
6 Models/CategoryAssign.php
View
@@ -25,4 +25,10 @@ class CategoryAssign extends \ActiveRecord\Model {
Array('post_id', 'maximum' => 11),
Array('category_id', 'maximum' => 11)
);
+
+ static $belongs_to = Array(
+ Array('category'),
+ Array('post')
+ );
+
}
5 Models/Post.php
View
@@ -23,6 +23,11 @@
namespace Void;
class Post extends \ActiveRecord\Model {
+ static $attr_accessible = Array('title', 'content');
+
+ static $has_many = Array(
+ Array('category_assign')
+ );
static $belongs_to = Array('user');
static $validates_presence_of = Array(
8 Views/categories/_category.tpl
View
@@ -0,0 +1,8 @@
+<div class="box category-title">
+ <h3 class="span-8">{=:aTag($category->name, Array('categories', 'show', $category->id))}</h3>
+ <menu class="span-5 last category-menu">
+ <li>{=:aTag('bearbeiten', Array('categories', 'edit', $category->id))}</li>
+ <li>{=:aTag('delete', Array('categories', 'delete', $category->id))}</li>
+ </menu>
+ <div class="clear"></div>
+</div>
18 Views/categories/_form.tpl
View
@@ -0,0 +1,18 @@
+{=:form('post', Array('categories', 'new'), function($f) use ($category){}
+ {$f->setModel($category)}
+ <fieldset>
+ <legend>{>$category->id === null ? "Create" : "Edit"} a Category</legend>
+ <div>
+ {=$f->label("name")}
+ {=$f->text_field("name")}
+ </div>
+
+ <div>
+ {=$f->label("parent category")}
+ </div>
+
+ <div>
+ {=$f->submit("Save")}
+ </div>
+ </fieldset>
+{})}
3  Views/categories/index.tpl
View
@@ -0,0 +1,3 @@
+{foreach($categories as $category):}
+ {=:render('categories/_category.tpl', Array('category' => $category))}
+{endforeach}
2  Views/categories/new.tpl
View
@@ -0,0 +1,2 @@
+{=:render('categories/_form.tpl', Array('category' => $category))}
+
2  Views/categories/show.tpl
View
@@ -0,0 +1,2 @@
+{=:render('categories/_category', Array('category' => $category))}
+{=:render('posts/index', Array('posts' => $category->posts))}
3  Views/layout/_flash.tpl
View
@@ -0,0 +1,3 @@
+{Flash::show(function($flash_message){}
+ <div class="{>$flash_message->getType()}">{>$flash_message->getMessage()}</div>
+{});}
13 Views/layout/application.tpl
View
@@ -20,14 +20,19 @@
<ul>
<li>{=:aTag("Home", null)}</li>
<li>{=:aTag("About", "pages/about")}</li>
- <li>{=:aTag("Categories", null)}</li>
+ <li>{=:aTag("Categories", "categories")}</li>
</ul>
</nav>
- <section class="push-1 span-16 clear">
+ <section class="push-1 span-15 clear">
+ {=:render('layout/_flash')}
{[$_content}
</section>
- <aside class="push-1 span-6 last">
- <h3>test</h3>
+ <aside class="push-2 span-6 last">
+ <h3>Actions</h3>
+ <ul>
+ <li>{=:aTag('create a post', Array('posts', 'new'))}</li>
+ <li>{=:aTag('create a category', Array('categories', 'new'))}</li>
+ </ul>
</aside>
<footer class="clear">
&copy; Copyright {>:copyright_year()} by Mogria | powered by <a href="http://github.com/mogria/void.php" target="_blank">void.php</a>
23 Views/posts/_form.tpl
View
@@ -0,0 +1,23 @@
+{=:form('post', Array('posts', 'new'), function($f) use ($post){}
+ {$f->setModel($post)}
+ <fieldset>
+ <legend>{>$post->id === null ? "Create" : "Edit"} a Post</legend>
+ <div>
+ {=$f->label("title")}
+ {=$f->text_field("title")}
+ </div>
+
+ <div>
+ {=$f->label("content")}
+ {=$f->text_area("content", Array('rows' => '5', 'cols' => '40'))}
+ </div>
+
+ <div>
+ {=$f->label("category")}
+ </div>
+
+ <div>
+ {=$f->submit("Save")}
+ </div>
+ </fieldset>
+{})}
4 Views/posts/_post_menu.tpl
View
@@ -0,0 +1,4 @@
+<menu class="box">
+ <li>{=:aTag("Delete this post", 'posts/delete/' . $post->id, Array('onclick' => 'return confirm("Do you really want to delete this post?")'))}
+ <li>{=:aTag("Edit this post", 'posts/edit/' . $post->id)}
+</menu>
1  Views/posts/edit.tpl
View
@@ -0,0 +1 @@
+{=:render('posts/_form', Array('post' => $post))}
1  Views/posts/new.tpl
View
@@ -0,0 +1 @@
+{=:render('posts/_form.tpl', Array('post' => $post))}
1  Views/posts/show.tpl
View
@@ -3,4 +3,5 @@
No post found
{else:}
{=:render('posts/_post', Array('post' => $post))}
+{=:render('posts/_post_menu', Array('post' => $post))}
{endif}
9 lib/Boot/Booter.php
View
@@ -16,9 +16,12 @@ class Booter extends JobCollection {
* Only this class can create instances of this class
*/
protected function __construct() {
- foreach(self::$config->classes as $class) {
- $class = __NAMESPACE__ . "\\" . $class;
- $this->add(new $class());
+ $types = Array('classes', isset($_SERVER['SHELL']) ? 'classes_shell' : 'classes_web');
+ foreach($types as $type) {
+ foreach(self::$config->$type as $class) {
+ $class = __NAMESPACE__ . "\\" . $class;
+ $this->add(new $class());
+ }
}
}
2  lib/HTML/LabelTag.php
View
@@ -10,7 +10,7 @@ public function __construct($name, $for, $attributes = Array()) {
if($name instanceof Model) {
$this->for = $for;
// call the proper method on the model to get the Columnname
- $this->setContent($name);
+ $this->setContent($for);
} else {
$this->setContent($name);
$this->for = $for;
26 stylesheets/layout/form.css
View
@@ -0,0 +1,26 @@
+input[type="text"], input[type="password"]{
+ width: 300px;
+}
+textarea {
+ width: 340px;
+}
+form fieldset > div {
+ clear: left;
+ display: block;
+}
+
+
+form fieldset > div > label {
+ display: block;
+ float: left;
+ width: 200px;
+}
+
+form fieldset > div > input[type="submit"] {
+ margin-left: 200px;
+}
+
+
+form fieldset > div > * + input[type="submit"] {
+ margin-left: auto;
+}

No commit comments for this range

Something went wrong with that request. Please try again.