Created
April 4, 2015 12:37
-
-
Save nepda/d572f9ad787c48c8555d 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 | |
namespace App { | |
include_once '../vendor/autoload.php'; | |
} | |
namespace App\Entity { | |
use Zend\Form\Annotation; | |
/** | |
* Class Model | |
* | |
* @package App\Entity | |
* @Annotation\Type("App\Form\BookForm") | |
*/ | |
class Model | |
{ | |
/** | |
* @var string | |
* @Annotation\Options({"label":"Your stuff"}) | |
*/ | |
protected $something; | |
/** | |
* @return string | |
*/ | |
public function getSomething() | |
{ | |
return $this->something; | |
} | |
/** | |
* @param string $something | |
* @return $this | |
*/ | |
public function setSomething($something) | |
{ | |
$this->something = $something; | |
return $this; | |
} | |
} | |
} | |
namespace App\Form { | |
use Zend\Form\Element\Submit; | |
use Zend\Form\Form; | |
class BookForm extends Form | |
{ | |
public function __construct() | |
{ | |
parent::__construct('my-form'); | |
$this->add(new Submit('submit', ['label' => 'save'])); | |
} | |
} | |
} | |
namespace App\Controller { | |
use App\Entity\Model; | |
use App\Form\BookForm; | |
use Zend\Form\Annotation\AnnotationBuilder; | |
use Zend\Mvc\Controller\AbstractActionController; | |
class IndexController extends AbstractActionController | |
{ | |
public function indexAction() | |
{ | |
$builder = new AnnotationBuilder(); | |
$entity = new Model(); | |
$form = $builder->createForm($entity); | |
if ($form instanceof BookForm) { | |
echo 'Book form' . PHP_EOL; | |
echo $form->get('submit')->getLabel() . PHP_EOL; | |
} else { | |
echo 'Not a book Form' . PHP_EOL; | |
} | |
} | |
} | |
$ctrl = new IndexController(); | |
$ctrl->indexAction(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer for stockoverflow question http://stackoverflow.com/questions/12002722/using-annotation-builder-in-extended-zend-form-class/29446505#29446505