How to use orderBy param on find_method findAll with Doctrine ObjectSelect

The docs offer an example for an extended version of the DoctrineModule\Form\Element\ObjectSelect:

This find_method parameters allow you to order and sort the result of your repository method.


Unfortunately this will not work when using the findAll method. But why?

Looking at the source code of the Doctrine ORM you can see that unlike the findBy method findAll does not allow passing arguments for filtering, sorting nor limiting:


But there is a workaround:

Use the findBy() method instead and simply pass an empty array for the criteria parameter.


That’s it!



How to render XML response in Zend Framework 2

Zend Framework 2 offers different Rendering and Response Strategies.

Unfortunately there is no out-of-the-box Strategy for XML.

Solely RSS Feeds are supported:

Well, there is a Module by Alessandro Pietrobelli:

If you want to render raw XML you can use these simple lines in your controller:


If you need to create complex XML files you can use the PHP XMLWriter which is included in ZF2:



Checking ACL in Zend Navigation when using custom view script

The ZF2 Zend Navigation View Helpers manual shows how to configure your navigation adding ACL.

It also shows how to manually render your navigation inside your view scripts or layout:

Or simply:

So far so good – all of your ACL should work fine and only allowed pages are rendered.

This behaviour changes when you render your pages partially. The manual shows this example code:

This way also not allowed pages will be rendered. In order to get ACL checked you need to use the accept() method:




Check Zend Navigation page permissions with ZfcRbac

Define your navigation adding pages and permissions:


Configure your guards and role_providers for ZfcRbac:


Create a Listener:


Create a Factory for the RbacListener:


Add your RbacListenerFactory to your ServiceManager;


And finally attach an event to the isAllowed method of the Zend Navigation View Helper:


Now, if you render your navigation inside your layout only the pages the user role is permitted to see should be rendered.