Check the result of your programmatically built SQL statement in ZF2

Wondering if the SQL statement you made in ZF2 is producing the results you were expecting when it is run? Here is a way to look at the results of your built statement: public function myTableFunction($data) { $select = new Select(); $select->columns( array ( ‘SUM_COST’ => new \Zend\Db\Sql\Expression ( ‘SUM(PRODCOST)’ ) ) ); $select->from(‘TABLE_NAME’); $select->where($data); […]

How To Speed up ZF2

Based on this video from Gary Hockin (http://blog.hock.in/2014/05/14/maximising-performance-in-zf2-phpuk/) and tips through [USER=8]@Alan Seiden[/USER] I have written this guide to help anyone speed up their ZF2 app. The biggest improvement I have seen so far has been going from the standard autoloader to the classmapautoloader. My load time has gone from 700-900ms (based on zenddevelopertools) to […]

How to Quickly Build A Model File Using Regex

When building a model file for ZF2 I have found it can be quite tedious unless you use the search / replace with regular expressions. I did some testing with this site: http://regex101.com/ Here is how it works for me. If I have a list of fields with each one on its own line: test1 […]

Loading Query Parameters From A Menu Option

I wanted to load default query parameters off a navigation menu selection. Checking for no values or something else all came with problems. The solution I came up with that works very well is to create a child route called ‘default’ for whichever menu option I wanted to load and when that child route is […]

Loading A Layout Because Of An Event

If you have an certain event where you want a different template load (for me it was a check to see if you were logged in and if not go to a login page layout) here is the code to do so in your module.php: //This contains my events I want to check for. public […]

Use Case For Breadcrumbs And Pagination Control

Here is a good example of how to handle either Breadcrumbs or Pagination Control in ZF2. Using method 1 for Breadcrumbs and method 2 for Pagination Control is probably the smartest way for both. Big thanks to Jurian Sluiman (Twitter @juriansluiman Website https://juriansluiman.nl/ ) for the help! // METHOD 1:   // layout.phtml   <div […]

Using ACL (Access Control List) with ZF2

I found a GREAT article on on ACL. I was pretty much able to plug and play it into my app. http://ivangospodinow.com/zend-framework-2-acl-setup-in-5-minutes-tutorial/ One key thing is if you are using a partial to render your menu you will have to put in some extra logic in the partial to make sure the menu item should […]

Working With Dollar Sign ($) and Number Sign (#) In Column Names

DB2 has an interesting ability that can change the way you work with it when you are trying to write PHP programs. DB2 allows a $ and # to be part of the name of columns. This can prove difficult when trying to access them as these symbols have drastically important meanings in other languages […]

Pass A Value From Your Module.php To Your Layout.phtml

Here is some simple code to pass values to your layout.phtml that will be global to your application. In your Module.php: public function onBootstrap($e) {   $viewModel = $e->getApplication()->getMvcEvent()->getViewModel(); $viewModel->yourValue = ‘Your Value’;   } In your layout.phtml $this->layout()->yourValue; Nice and easy!

How To Keep Query Parameters With Pagination

I haven’t found a good example of this so I thought I would write one up. If you have a list of items that you organize / filter and then want to paginate over you want to pass your query parameters and the page you are on. For reference this is the pagination example before […]