Understanding the stack index for Zend Framework Controller plugins

Zend Framework Controller plugins are a powerful way to inject logic into your controller system at various points, such as before and after an action dispatch. Plugins are run in the order they are added, though it is possible to change the order by defining a custom stack index. ZF internal plugins such as Zend_Controller_Plugin_ErrorHandler, which displays a nice Error 404 page, has a stack index of 100 to ensure it runs near the end of any plugin cycle. However, it’s not so obvious from the ZF manual how to set a custom stack index.
For example, you may have a common admin system layout that does various things to your admin page layout before the page is displayed. This could be registered in your controller as so:

If you want to alter the plugin so it runs after any other local plugins you could specify a stack index of 10 as a second argument:

$front->registerPlugin($adminLayout, 10);

However, unless you know what the existing plugin stack indexes are it’s difficult to know what stack index you should be using. You can use this small code snippet to output the plugin name and its associated stack index, again via your controller.