dev-master
9999999-dev https://github.com/fabiopaiva/Zf2DoctrineAutocompleteProvides a autocomplete form for ZF2 and Doctrine2.
MIT
The Requires
- php >=5.3.3
- doctrine/doctrine-module >=0.8
by Fábio Paiva
zf2
Wallogit.com
2017 © Pedro Peláez
Provides a autocomplete form for ZF2 and Doctrine2.
A form element autocomplete for Doctrine 2 and ZF2, (*1)
DoctrineModule, jQuery, jQueryUi,, (*2)
cd vendor git clone https://github.com/fabiopaiva/Zf2DoctrineAutocomplete
php composer.phar require fabiopaiva/zf2-doctrine-autocomplete:dev-master
# if composer cp vendor/fabiopaiva/zf2-doctrine-autocomplete/data/zf2-doctrine-autocomplete.min.js public/js/ # if github cp vendor/Zf2DoctrineAutocomplete/data/zf2-doctrine-autocomplete.min.js public/js/
Enable this module in your application.config.php, (*3)
return array(
'modules' => array(
'DoctrineModule',
'Zf2DoctrineAutocomplete',
'Application',
)
);
Copy this file from data folder, (*4)
echo $this
->headScript()
->prependFile($this->basePath() . '/js/zf2-doctrine-autocomplete.min.js');
This file must be statically configured because is called from Zf2DoctrineAutocomplete engine, (*5)
<?php
namespace Application\Form\Element;
use Zf2DoctrineAutocomplete\Form\Element\ObjectAutocomplete;
class MyAutocompleteElement extends ObjectAutocomplete {
private $initialized = false;
public function setOptions($options) {
if (!$this->initialized) {
$options = array_merge($options, array(
'class' => get_class($this),
'object_manager' => $options['sm']->get('Doctrine\ORM\EntityManager'), // For Doctrine ORM
// 'object_manager' => $options['sm']->get('doctrine.documentmanager.odm_default'), // For Doctrine ODM (Mongodb)
'target_class' => 'Application\Entity\MyEntity',
'searchFields' => array('code', 'description'),
'empty_item_label' => 'Nothing found',
'select_warning_message' => 'Select a itemName in list',
'property' => 'description',
'orderBy' => array('code','ASC')
));
$this->initialized = true;
}
parent::setOptions($options);
}
}
$form->add(array(
'name' => 'myAutocompleteElement',
'type' => 'Application\Form\Element\MyAutocompleteElement',
'options' => array(
'label' => 'My label here',
'sm' => $serviceManager // don't forget to send Service Manager
),
'attributes' => array(
'required' => true,
'class' => 'form-control input-sm'
)
));
After add the new element in page, call the initializer:, (*6)
zf2DoctrineAutocomplete.init('#jQuerySelector');
Provides a autocomplete form for ZF2 and Doctrine2.
MIT
zf2