Created
July 9, 2012 12:34
-
-
Save awartoft/3076219 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* @author Jonas Eriksson <[email protected]> | |
* @author Antoine Hedgecock <[email protected]> | |
*/ | |
/** | |
* | |
*/ | |
namespace Article\Form\Admin; | |
use Zend\ServiceManager\ServiceManager, | |
Zend\ServiceManager\ServiceManagerAwareInterface, | |
Zend\Form\Form, | |
Zend\InputFilter\InputFilter; | |
class Create extends Form implements ServiceManagerAwareInterface | |
{ | |
public function __construct() | |
{ | |
parent::__construct('article_create'); | |
$this->setAttribute('method', 'post') | |
->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods()) | |
->setInputFilter(new InputFilter()); | |
$this->add(array( | |
'type' => 'Article\Form\Fieldsets\ArticleFieldset', | |
'options' => array( | |
'use_as_base_fieldset' => true | |
) | |
)); | |
} | |
/** | |
* @param ServiceManager $serviceManager | |
*/ | |
public function setServiceManager(ServiceManager $serviceManager) | |
{ | |
// Set the hydrator from the service manager | |
$this->setHydrator($serviceManager->get('EntityHydrator')); | |
$categories = $serviceManager->get('article_service_category') | |
->fetchAll(array('sort' => array('name' => 'ASC'))); | |
foreach($categories as $category) { | |
$values[$category['name']] = $category['id']; | |
} | |
// Get the fieldset and set the categories.. | |
$this->get('article') | |
->get('category_id') | |
->setAttribute('options', $values); | |
$this->get('article') | |
->get('author') | |
->setAttribute('value', $serviceManager->get('user_service_auth')->getIdentity()->getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment