zend-framework2

ZF2: Equivalent of getServiceLocator in Zend Form

狂风中的少年 提交于 2019-12-04 16:59:39
assumption: Event\Service\EventService is my personal object that works with Event\Entity\Event entities This code works in an ActionController: $eventService = $this->getServiceLocator()->get('Event\Service\EventService'); How can I get $eventService in a Zend\Form\Form in the same way? You have two options if you have a dependency like this. In your case, a Form depends on a Service . The first option is to inject dependencies : class Form { protected $service; public function setService(Service $service) { $this->service = $service; } } $form = new Form; $form->setService($service); In this

PHPUnit bootstrap in PhpStorm

◇◆丶佛笑我妖孽 提交于 2019-12-04 15:04:44
问题 I am working with Zend Framework 2 and I want to run tests for all of my modules in PhpStorm 5.0.4. I have PhpStorm set up to check for tests in myproject/module and it successfully finds my tests. The problem is that it doesn't read my configuration file within each module, which is needed (it points to a bootstrap file). Here is the directory structure for a module (source): /module /User /tests /UserTest /Model /UserTest.php Bootstrap.php phpunit.xml.dist TestConfig.php.dist When I run the

Zend Framework Multi Language Integration Steps

雨燕双飞 提交于 2019-12-04 15:03:34
问题 I am new to zend framework2 and I am working on a site with multi language integration. Please give me the idea about, how the builtin library and translation file should be configured, and how its can be called from view file 回答1: ZF2 has already integrated I18n tools. How to integrate it module.config.php 'translator' => array( 'locale' => 'en_US', 'translation_file_patterns' => array( array( 'type' => 'gettext', 'base_dir' => __DIR__ . '/../language', 'pattern' => '%s.mo', ), ), ), Files *

ZF2 - subqueries

走远了吗. 提交于 2019-12-04 14:14:39
问题 Subquery in Zend Framework 2 My required query: SELECT `comment`.`id` AS `commentId`, `comment`.`comment` AS `comment`, (SELECT COUNT(`comment_vote`.`id`) AS `negativeVote` FROM `comment_vote` WHERE vote = -1 AND `comment_vote`.`commentId` = `comment`.`id`) AS `nagetiveVoteCount` FROM `comment` Please help. Thanks, Anjith 回答1: My required Query: SELECT `comment`.`id` AS `commentId`, `comment`.`comment` AS `comment`, (SELECT COUNT(comment_vote.id) AS `negativeVote` FROM `comment_vote` WHERE

Append Javascript File to the end of the InlineScript Collection from child view

落爺英雄遲暮 提交于 2019-12-04 14:13:00
问题 I'm working with Zend Framework 2. In my Layout File i inject some javascript files like this: $this->InlineScript() ->appendFile($this->basePath() . '/js/myfile.js'); echo $this->InlineScript(); Now i want to inject some javascript from a view so that it appends to the end of the InlineScript Collection. So i wrote this in my action view: <?php $this->InlineScript()->offsetSetFile(100,$this->basePath() . '/js/xyz.js'); ?> But the result is the File xyz is loaded first in the rendered view. I

Entity exist validation in Zend Framework 2 with Doctrine 2 using inputfilter in entity

耗尽温柔 提交于 2019-12-04 14:01:34
问题 I have been building my all validation in Entity class like this... class User { protected $inputFilter; public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array( 'name' => 'username', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' =>'NotEmpty', 'options' => array( 'messages' => array(

Getting request Authorization header in ZF2 controller

早过忘川 提交于 2019-12-04 13:57:08
I am using ZF2 and for some reason, I can get all the headers I send EXCEPT the Authorization header - it's like its filtered out. I am trying to get all the headers in the controller like this: public function createAction($data) { $request = $this->request; print_r ($request->getHeaders()); exit(); } I send the request through cURL like this: curl -i -H "Accept: test" -H "Authorization: 123456" -H "Content-Type: qwerty" -X POST http://localhost/test All headers prints out EXCEPT authorization header. I can add any arbitrary header and it prints it out - just no the 'Authorization' header...

ZF2 Translation

谁说我不能喝 提交于 2019-12-04 13:46:21
I have two modules - Application and StickyNotes. I need to use translation on all pages. What I do: 1) In view: <?=$this->translate('Home');?> 2) In Application\Module.php: public function onBootstrap(MvcEvent $e) { $translator = $e->getApplication()->getServiceManager()->get('translator'); $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $app = $e->getParam('application'); $app->getEventManager()->attach('render', array($this, 'setLayoutTitle')); $translator->setLocale('ru_RU'); echo

ZF2 Service Locator

最后都变了- 提交于 2019-12-04 13:20:52
I'm quite new to zf2 and I'm experimenting with it. I have a view helper and I need it to access a table object. In my controller I can run: $this->getServiceLocator(); But ideally I would run this inside my view helper. Unfortunately, I can't seem to access it from within my view helper. I tried passing it through the constructor, configuring a factory method in module.config.php, but when I try that, Zend will no longer pass a tablegateway object into one of my model objects created from a service factory method in the module's Module.php file. This seems to be because it no longer calls the

The hydrator settings are ignored in Apigility

让人想犯罪 __ 提交于 2019-12-04 13:20:11
In Apigility it's possible to set a Hydrator for every Entity -- either over the Apigility UI or directly in the module.config.php , e.g.: return array( ... 'zf-hal' => array( 'metadata_map' => array( 'Portfolio\\V2\\Rest\\Project\\ProjectEntity' => array( 'entity_identifier_name' => 'id', 'route_name' => 'portfolio.rest.project', 'route_identifier_name' => 'id', 'hydrator' => 'Zend\\Stdlib\\Hydrator\\ObjectProperty', // 'hydrator' => 'MyNamespace\\Hydrator\\ProjectHydrator', ), ... ), ... ), ... ); See also the documentation . Currently I'm using the ClassMethods hydrator for all my entities.