Created
May 2, 2013 16:25
-
-
Save wyanez/5503392 to your computer and use it in GitHub Desktop.
ZF2 Snippets
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 | |
$form->prepare(); | |
echo $this->form()->openTag($form); | |
echo $this->formRow($form->get('campo')); | |
//... resto de campos | |
// o echo $this->formCollection($form); | |
echo $this->formSubmit($form->get('submit')); | |
?> | |
<a href="<?= $this->url('mi_controlador', array('action' =>'mi_accion'))?>">Regresar</a> | |
<?php | |
echo $this->form()->closeTag(); | |
?> |
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 | |
namespace MiModulo\Controller; | |
use Zend\Mvc\Controller\AbstractActionController; | |
use Zend\View\Model\ViewModel; | |
class MyController extends AbstractActionController | |
{ | |
public function indexAction() | |
{ | |
return new ViewModel(); | |
} | |
} | |
?> |
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 | |
namespace MiModulo\Form; | |
use Zend\InputFilter\Factory as InputFactory; | |
use Zend\InputFilter\inputFilter; | |
use Zend\InputFilter\inputFilterAwareInterface; | |
use Zend\InputFilter\InputFilterInterface; | |
class MyFilter implements InputFilterAwareInterface{ | |
protected $inputFilter; | |
public function setInputFilter(InputFilterInterface $inputFilter){ | |
throw new \Exception("No implementado"); | |
} | |
public function getInputFilter(){ | |
if(!$this->inputFilter){ | |
$inputFilter =new inputFilter(); | |
$factory = new InputFactory(); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'nombre_campo', | |
'required' => true, | |
'filters' => array( | |
array('name'=>'StripTags'), | |
array('name'=>'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options'=>array( | |
'encoding' =>'UTF-8', | |
'min'=>1, | |
'max'=>100 | |
), | |
), | |
), | |
))); | |
//... resto de validaciones | |
$this->inputFilter = $inputFilter; | |
} | |
return $this->inputFilter; | |
} | |
} | |
?> |
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 | |
namespace MiModulo\Form; | |
use Zend\Form\Form; | |
class MyForm extends Form{ | |
public function __construct($name='name_form'){ | |
parent::__construct($name); | |
$this->setAttribute('method','post'); | |
$this->add( array( | |
'name' => '', | |
'type' => '', | |
'options' => array( | |
'label' => '', | |
), | |
)); | |
$this->add( array( | |
'name' => 'submit', | |
'type' => 'Submit', | |
'options' => array( | |
'value' => 'Aceptar', | |
'id' => 'submitbutton', | |
), | |
)); | |
} | |
} |
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 | |
namespace MiModulo\Model; | |
class MyModel{ | |
public $campo; | |
//... resto de campos | |
public function exchangeArray($data){ | |
$this->campo = (isset($data['campo'])) ? $data['campo'] : null; | |
//... resto de campos | |
} | |
//requerido por el Hydrator: Zend\Stdlib\Hydrator\ArraySerializable | |
public function getArrayCopy(){ | |
return get_object_vars($this); | |
} | |
} | |
?> |
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 | |
namespace MiModulo\Model; | |
use Zend\Db\TableGateway\TableGateway; | |
class MyTable{ | |
protected $tableGateway; | |
public function __construct(TableGateway $tableGateway){ | |
$this->tableGateway = $tableGateway; | |
} | |
public function fetchAll(){ | |
$resultSet = $this->tableGateway->select(); | |
return $resultSet; | |
} | |
//... resto de los metodos | |
} | |
?> |
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 | |
$title = 'Titulo de la Pagina'; | |
$this->headTitle($title); | |
?> | |
<h2><?php echo $this->escapeHtml($title); ?></h2> | |
<a href="<?= $this->url('mi_controller', array('action'=>'mi_accion'));?>"> Hiperlink </a> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment