zend-framework2

zf2 ServiceManager vs ServiceLocator

蓝咒 提交于 2019-12-12 10:29:05
问题 I am learning zf2, reading docs, tutorials etc from the web. Now I am confused regarding Zend\ServiceManager\ServiceManagerAwareInterface.php and Zend\ServiceManager\ServiceLocatorAwareInterface.php . Also in some place (like controller) I use $this->getServiceLocator() to fetch the ServiceManager object while at some other places we use ->getServiceManager() and it also returns the same ServiceManager object. 回答1: The Locator is the interface. The design of Zend Framework 2 is done with

Zend Framework 2 - Annotation form, RegEx validation and custom error messages

旧时模样 提交于 2019-12-12 10:12:18
问题 As outlined here I'm working with GeoPositionFields . Because this is not supported from Zend, I went with a standard RegEx validator. It works great but I still need a custom error message - any ideas how to achieve this? The one in my example just does nothing... /** * @ORM\Column(type="string") * @Form\Filter({"name":"StringTrim"}) * @Form\Validator({"name":"Regex", "options":{"pattern":"/(-?\d{1,3}\D\d+)[^\d-]+(-?\d{1,3}\D\d+)/"}}) * @Form\ErrorMessage("My custom message") * @Form

Zend Framework 2: Zend_Navigation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 09:27:17
问题 I am just wondering what would be the best way, to use Zend_Navigation in Zend Framework2. At the moment i am trying to a add a Config for a Header and a Footer Menu. Both Menus should be populated automatically. Though, i have run into a lot of Problems: a) The best place for the Default Menu should be hopefully the Application-Module b) I added the following to the root of module.config.php: 'view_helpers' => array( 'helper_map' => array( 'navigation' => 'Application\View\Helper\Navigation'

Zend Framework 2 SOAP AutoDiscover and complex types

╄→尐↘猪︶ㄣ 提交于 2019-12-12 08:44:50
问题 I'm preparing the SOAP server and generating my WSDL using the follow code: //(... Controller action code ...) if (key_exists('wsdl', $params)) { $autodiscover = new AutoDiscover(); $autodiscover->setClass('WebServiceClass') ->setUri('http://server/webserver/uri'); $autodiscover->handle(); } else { $server = new Server(null); $server->setUri($ws_url); $server->setObject($this->getServiceLocator()->get('MyController\Service\WebServiceClass')); $server->handle(); } //(... Controller action code

Set ttl and namespace using Memcached in Zend Framework 2

冷暖自知 提交于 2019-12-12 08:17:07
问题 As far as I can figure this seems to be the way to set up Memcached and set the TTL and Namespace but they have no effect in the cache. The key is not prefixed with a namespace and the expire is infinite. $MemcachedOptions = new \Zend\Cache\Storage\Adapter\MemcachedOptions(); $MemcachedResourceManager = new \Zend\Cache\Storage\Adapter\MemcachedResourceManager(1, new \Zend\Cache\Storage\Adapter\Memcached()); $MemcachedResourceManager->addServer(1, array('localhost', 11211)); $MemcachedOptions-

How to validate a checkbox in ZF2

对着背影说爱祢 提交于 2019-12-12 08:12:29
问题 I've read numerous workarounds for Zend Framework's lack of default checkbox validation. I have recently started using ZF2 and the documentation is a bit lacking out there. Can someone please demonstrate how I can validate a checkbox to ensure it was ticked, using the Zend Form and Validation mechanism? I'm using the array configuration for my Forms (using the default set-up found in the example app on the ZF website). 回答1: Try this Form element : $this->add(array( 'type' => 'Zend\Form

How to get controller and action name in zf2

随声附和 提交于 2019-12-12 08:08:57
问题 in zf1, we can get controller and action name using $controller = $this->getRequest()->getControllerName(); $action = $this->getRequest()->getActionName(); How we can achieve this in zf2? UPDATE: I tried to get them using echo $this->getEvent()->getRouteMatch()->getParam('action', 'NA'); echo $this->getEvent()->getRouteMatch()->getParam('controller', 'NA'); But I am getting error Fatal error: Call to a member function getParam() on a non-object I like to get them in __construct() method;

How do I pass variables to another action from a search form?

自闭症网瘾萝莉.ら 提交于 2019-12-12 05:59:35
问题 I have two search pages. One is a condensed search form the other is an advanced search. I would like the user to enter their search at on the condensed page and be redirected to the results page which contains the advanced search fields. The two issues I currently have are: How do I redirect? What is the best practice for when a field is left blank? Currently, I keep looking back to the index to get the first two search fields Condensed Search public function indexAction() { $dbAdapter =

ZF2 + Doctrine 2 - Entity created when requirements not met and values empty

南笙酒味 提交于 2019-12-12 05:47:26
问题 Extending on 2 previous questions about form structure and validating collections I've run into the next issue. My form validates properly. Including included collections by way of Fieldsets. But the innermost Fieldset should not result in an Entity and a FK association to the parent if its values are not set. An Address may or may not have linked Coordinates . It's possible to create all of these in the same Form. However, the Coordinates should not be created and should not be linked from

Using the ServiceLocator in ZF2 with Doctrine 2 from/in a Custom Class?

我怕爱的太早我们不能终老 提交于 2019-12-12 05:42:14
问题 i have a little problem using doctrine 2 in Zend Framework 2 i have custome class that i use to manipulate doctrine generated model (basically to inject data and populate), to make that work i need the entity manager which is available through the service manager as indicated in Jason Grimes tutorial here http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/. In his tutorial it works (i tested it) as the ServiceLocator is called from a controller class, but for the