zend-framework2

ZF2 Add custom attribute to option in a select form element

喜你入骨 提交于 2021-02-08 12:58:36
问题 I would like to add a custom HTML attribute to an option of a select in a Zend Framework 2 Form. This is my (partial) code from my Form class: $this->add(array( 'name' => 'lieuRemplissage', 'type' => 'Select', 'attributes' => array( 'class' => 'form-control', ), 'options' => array( 'label' => _('Lieu pré-enregistré'), ), )); I populate my options values in my controller like this : $form = new \Vente\Form\Vente; foreach($this->getAdminLieuDeVenteTable()->fetchAll() as $lieu) { $optionsLieu[

How to fix 'The input was not found in the haystack' in ZF2?

限于喜欢 提交于 2021-01-29 08:38:48
问题 I have an issue in my code which I can't resolve. I'm using Zend framework 2.4 and I wrote a form but as soon as I validate it, I got the error The input was not found in the haystack . This are the 3 input where I got the error: $this->add(array( 'name' => 'ACTIVITE1', 'type' => 'Zend\Form\Element\Select', 'required' => 'required', 'options' => array( 'value_options' => array( 'Choisir l\'activité' ), 'disable_inarray_validator' => false, ), 'attributes' => array( 'class' => 'form-control',

Zend Framework 2 - Join tables in different databases and schemas

守給你的承諾、 提交于 2020-06-28 10:57:23
问题 In Zend Framework 2 when I want to make a join between different database tables I have to use the \Zend\Db\Sql\TableIdentifier class to avoid an incorrect escaping. If I do in this way: $select->join(['B' => 'database2.table2'], 'A.id = B.id'); It is rendered as: SELECT [..] FROM "table" as "A" INNER JOIN "database2.table2" ON [...] This causes an incorrect quoting "database2.table2" To solve this situation I can do: $tbl2 = new \Zend\Db\Sql\TableIdentifier('table2', 'database2'); $select-

Compress html output from zend framework 2

痞子三分冷 提交于 2020-04-13 09:01:11
问题 I'm currently using Zend Framework 2 beta for on PHP 5.4.4 to develop a personal webapp for self-study purpose. I was wondering if it is possible to intercept the html output just before it is sent to the browser in order to minify it by removing all unnecessary white spaces. How could I achieve this result in ZF2? 回答1: Yep, you can: On Modle.php create an event that will trigger on finish public function onBootstrap(Event $e) { $app = $e->getTarget(); $app->getEventManager()->attach('finish'

ZF2 - Checking permissions for get parameter in each action

只谈情不闲聊 提交于 2020-04-07 09:33:44
问题 I have a Controller called "TestController" and several actions in it. For each action I receive a get Parameter ("id"). Something like: test/action1/1 test/action1/2 test/action2/1 test/action3/1 ... Since this parameter can easily be modified I want to check the permissions for this id. Do I have to include this check method in each single action or is there another way? I know that I can't receive params in the constructor but a way like this would be nice. My solution at the moment would

ZF2 - Checking permissions for get parameter in each action

ε祈祈猫儿з 提交于 2020-04-07 09:31:26
问题 I have a Controller called "TestController" and several actions in it. For each action I receive a get Parameter ("id"). Something like: test/action1/1 test/action1/2 test/action2/1 test/action3/1 ... Since this parameter can easily be modified I want to check the permissions for this id. Do I have to include this check method in each single action or is there another way? I know that I can't receive params in the constructor but a way like this would be nice. My solution at the moment would

Gearman, ZF2, Doctrine2, MySQL, SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

大城市里の小女人 提交于 2020-02-28 06:59:53
问题 I use ZF2, Doctrine2, MySQL, Gearman. When working Gearman periodically has an error: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away. I tried these steps to fix the problem: 1) I investigated MySQL queries. Queries haven't any problem. It's simple (without subqueries) and fast. For example, this is EXPLAIN of one of queries when MySQL server has gone away. +-------------+-------+-------+-----------------------+-----------------------+---------+-------+------+ | select_type |

Doctrine2 bulk import try to work with another entity

倾然丶 夕夏残阳落幕 提交于 2020-02-24 11:19:07
问题 I'm working on a members import batch (with insertions and updates) for a big project with a lot of entities such as Member , Client , Group , ... . After reading the chapter related to bulk imports in Doctrine doc, I've implemented this code : $batchSize = 20; $i = 0; foreach ($entities as $entity) { $this->getEntityManager()->persist($entity); if (($i % $batchSize) === 0) { $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); } } $this->getEntityManager()->flush(); $this-

Best and secure way to send parameters in URL

倾然丶 夕夏残阳落幕 提交于 2020-02-20 04:33:31
问题 I am working on a website in which there would be functionalities to update and delete data on the basis of id. Now the thing I am worried about is like my url would be www.example.com/public/controller/action/1 if the action would be delete , any person can change id from 1 to 2 in url and the data with id 2 would get deleted. What would be the best way to keep the flow secure. I am using Zf2 and Doctrine2... Any suggestions please !!! And moreover I am keeping ids hidden in fields, anybody

Zend Form Rendering and Decorators (Use correctly with bootstrap)

余生颓废 提交于 2020-02-02 14:00:50
问题 The Bootstrap Example Code http://getbootstrap.com/css/#forms Copying a simple email input element from getbootstrap.com suggests we format the HTML in the following way: <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input id="exampleInputEmail1" class="form-control" type="email" placeholder="Email"> </div> Above we have a <label> tag that closes straight after it's text content, "Email address". I would now like to create the same form group using Zend