Created
February 12, 2011 10:15
-
-
Save blar/823669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Form, | |
Blar\Model\News\Article, | |
Blar\Model\News\Articles; | |
class News_IndexController extends Zend_Controller_Action { | |
protected $entityManager; | |
public function init() { | |
$registry = Zend_Registry::getInstance(); | |
$this->entityManager = $registry->entityManager; | |
$this->view->headTitle('Nachrichten'); | |
$this->view->headLink(array( | |
'rel' => 'alternate', | |
'href' => $this->view->url(array('type' => 'atom')), | |
'type' => 'application/atom+xml', | |
'title' => 'Nachrichten als ATOM-Feed' | |
)); | |
$this->view->headLink(array( | |
'rel' => 'alternate', | |
'href' => $this->view->url(array('type' => 'rss')), | |
'type' => 'application/rss+xml', | |
'title' => 'Nachrichten als RSS-Feed' | |
)); | |
} | |
public function indexAction() { | |
$page = $this->getRequest()->getParam('page'); | |
$paginator = Articles::getRecentByPage($page); | |
$this->view->articles = $paginator; | |
$this->view->paginator = $paginator; | |
} | |
public function editAction() { | |
$user = $this->entityManager->getRepository('Blar\\Model\\User')->findOneByName('Blar'); | |
$form = new Form; | |
$form->addElement('text', 'title', array( | |
'belongsTo' => 'article', | |
'label' => 'Titel', | |
'size' => 80, | |
'required' => true | |
)); | |
$form->addElement('textarea', 'teaser', array( | |
'belongsTo' => 'article', | |
'label' => 'Teaser', | |
'cols' => 80, | |
'rows' => 8, | |
'required' => true | |
)); | |
$form->addElement('textarea', 'content', array( | |
'belongsTo' => 'article', | |
'label' => 'Inhalt', | |
'cols' => 80, | |
'rows' => 20, | |
'required' => true | |
)); | |
$form->addElement('checkbox', 'comments', array( | |
'label' => 'Kommentare', | |
'description' => 'Kommentare erlauben', | |
'value' => true | |
)); | |
$form->addElement('checkbox', 'twitter', array( | |
'label' => 'Twitter', | |
'description' => 'Auf Twitter veröffentlichen' | |
)); | |
$form->addElement('text', 'created', array( | |
'belongsTo' => 'article', | |
'label' => 'Erstellungsdatum', | |
'description' => 'Nur ausfüllen, wenn sich das Erstellungsdatum unterscheidet' | |
)); | |
$form->addElement('submit', 'create', array( | |
'label' => 'Erstellen' | |
)); | |
$this->view->form = $form; | |
if(!$this->getRequest()->isPost()) { | |
return false; | |
} | |
if(!$form->isValid($_POST)) { | |
return false; | |
} | |
$article = new Article($_POST['article']); | |
$article->setUser($user); | |
$article->save(); | |
$form->reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment