Skip to content

Instantly share code, notes, and snippets.

@bcho
Created February 8, 2015 02:16
Show Gist options
  • Select an option

  • Save bcho/b9f0e7fafc8ff3a85a9b to your computer and use it in GitHub Desktop.

Select an option

Save bcho/b9f0e7fafc8ff3a85a9b to your computer and use it in GitHub Desktop.
<?php
use Widget\Form;
use Widget\Checkbox;
class ProductPresenter {
protected $resource;
public function withProduct($product)
{
$this->resource = $product;
return $this;
}
/**
* @return string
*/
public function render()
{
return $this->renderForm();
}
/**
* @return string
*/
protected function renderForm()
{
$checkbox = new Checkbox();
$checkbox->setOptions([
1 => 'Category 1',
2 => 'Category 2'
]);
// $checkbox->setValue(...)
return (new Form($this->resource))
->attributes(['class' => 'product-form'])
->action('/product', ['method' => 'post'])
->add('name', 'text') // sub-widget
->add('image', 'file') // sub-widget
->add('category', $checkbox)
->add('submit', 'submit')
->render();
}
}
@bcho
Copy link
Copy Markdown
Author

bcho commented Feb 8, 2015

FYI @cnsaturn

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