Skip to content

Instantly share code, notes, and snippets.

@Cacodaimon
Created October 2, 2012 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cacodaimon/3822739 to your computer and use it in GitHub Desktop.
Save Cacodaimon/3822739 to your computer and use it in GitHub Desktop.
<?php
class BlogController extends Zend_Controller_Action
{
public function indexAction()
{
try {
$model = new Application_Model_Article;
$this->view->articles = $model->fetchAll();
}
catch (Exception $e) {
$this->view->error = $e->getMessage();
}
}
public function articleAction()
{
$model = new Application_Model_Article;
$this->view->article = $model->find(
$this->getRequest()->getParam('_id')
);
$this->view->postCommentForm = new Application_Form_Comment(array(
'_id' => $model->_id,
));
}
public function postcommentAction()
{
$form = new Application_Form_Comment;
if (!$form->isValid($data = $this->getRequest()->getParams())) {
$form->populate($data);
$this->_redirect('/blog/', array('exit', true));
}
$article = new Application_Model_Article;
$article->find($data['_id']);
$article->addComment(new Application_Model_Comment(array(
'text' => $data['text'],
'autor' => $data['autor'],
'date' => new MongoDate(time()),
)));
$this->_redirect('/blog/article/_id/' . $data['_id']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment