Skip to content

Instantly share code, notes, and snippets.

@awartoft
Created July 9, 2012 12:34
Show Gist options
  • Save awartoft/3076219 to your computer and use it in GitHub Desktop.
Save awartoft/3076219 to your computer and use it in GitHub Desktop.
<?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