Skip to content

Instantly share code, notes, and snippets.

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 nepda/d572f9ad787c48c8555d to your computer and use it in GitHub Desktop.
Save nepda/d572f9ad787c48c8555d to your computer and use it in GitHub Desktop.
<?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();
}
@nepda
Copy link
Author

nepda commented Apr 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment