Permalink
Browse files

adding edit form.

  • Loading branch information...
1 parent f6241d4 commit c8477d874891d279f39149ef9c3449b0db6648bc @gwoo gwoo committed Dec 2, 2012
Showing with 49 additions and 4 deletions.
  1. +6 −4 controllers/PostsController.php
  2. +8 −0 views/posts/comment.html.php
  3. +35 −0 views/posts/edit.html.php
@@ -86,18 +86,20 @@ public function endorse($_id = null) {
public function edit($_id = null) {
$post = Posts::find($_id);
- if (empty($post)) {
+ $user = Session::read('user', array('name' => 'li3_user'));
+
+ if (empty($post) || $post->user_id != $user['_id']) {
return $this->redirect(array('controller' => 'posts', 'action' => 'index'));
}
if (!empty($this->request->data)) {
if ($post->save($this->request->data)) {
$this->redirect(array(
- 'controller' => 'posts', 'action' => 'view',
- 'args' => array($post->_id)
+ 'controller' => 'posts', 'action' => 'comment', '_id' => $post->_id
));
}
}
- return compact('post');
+ $tags = Posts::$tags;
+ return compact('post', 'tags');
}
}
@@ -25,6 +25,14 @@
<?php echo implode(", \n", array_unique($tags)); ?>
</span>
<?php } ?>
+ <?php
+ $session = $this->user->session();
+ if ($post->user()->_id == $session['_id']) {
+ echo "<span style='clear:right;float:right;display:block; padding: 0 14px;'>";
+ echo $this->html->link('edit', array("Posts::edit", "args" => array($post->_id)));
+ echo "</span>";
+ }
+ ?>
</aside>
</div>
@@ -0,0 +1,35 @@
+<div class="post" id="add-post">
+
+ <h1><?php echo $this->title('Edit Post')?></h1>
+
+<?php
+ $errors = $post->errors();
+ if (!empty($errors)) {
+ echo "<h2>There were errors tring to save your post.</h2>";
+ echo "<ul>";
+ foreach ($errors as $field => $_errors) {
+ foreach ($_errors as $error) {
+ echo "<li>{$error}</li>";
+ }
+ }
+ echo "</ul>";
+ }
+?>
+ <?php echo $this->form->create($post); ?>
+ <label for="PostTitle">Title:</label>
+ <?php echo $this->form->text('title', array('id' => 'PostTitle')); ?>
+ <label for="PostContent">Content:</label>
+ <?php echo $this->form->textarea('content', array('id' => 'PostContent', 'class' => 'custom-vertical-scroll')); ?>
+ <div class="base-tags">
+ <label class="label">Primary Tag:</label>
+ <?php foreach ($tags as $tag) { ?>
+ <?php echo $this->html->link($tag, "/{$tag}", array('title' => $tag, 'class' => "icon tag $tag", 'data-tag' => $tag)); ?>
+ <?php } ?>
+ </div>
+ <label for="PostTags" class="tags">Tags:</label>
+ <?php echo $this->form->text('tags', array('id' => 'PostTags')); ?>
+ <small class="post-notes">separate tags with commas.</small>
+ <?php echo $this->form->submit('save'); ?>
+ <?php echo $this->form->end(); ?>
+
+</div>

0 comments on commit c8477d8

Please sign in to comment.