Changing Layout in ZF2 Controller

November 15, 2015 by

Changing the layout or template within a Zend Framework 2 is easy. Thanks to the layout controller plugin, one can change the layout for a given controller action in just one line. public function indexAction() { $this->layout(‘layout/default’); return new ViewModel(); } As you can see above, the only thing you have to do in order… read more

Get Base Url within ZF2 Controller

November 15, 2015 by

Getting the base url of a request in Zend Framework 2 is quite simple. Because you are probably extending the AbstractActionController class, you get some functionality out of the box, including easily accessing the current request. From the request, one can get the URI, which exposes various methods for different parts of the URI. In… read more

Getting URL Parameters in ZF2 Controllers

November 13, 2015 by

Accessing URL parameters from controllers in Zend Framework 2 is extremely easy thanks to the params controller plugin. This plugin exposes various methods that one can use to retrieve parameters from various sources of a request, including from the URL. I will give examples of the various sources below. Getting URL Parameters To get URL… read more

Enum to Integer and Integer to Enum in Java

November 5, 2015 by

Need to convert an integer to an enum in Java? The bad news is that it is not as easy as it should be, but the good news is that it is still easy! Consider the enum below. public enum PageType { ABOUT(1), CODING(2), DATABASES(3); private int value; private static Map map = new HashMap();… read more

PostgreSQL Last Insert ID Not Working With PDO

November 5, 2015 by

If you are using PostgreSQL with PHP’s PDO for database connectivity, you might have experienced that the lastInsertId method on the database handler returns FALSE after inserting a row into the database. This can cause a lot of frustration, and this is one of the scenarios where PDO is not so database vendor independent. For… read more

Replacing Newline Characters in Java and JSTL

October 26, 2015 by

In this article, we will take a look at how we can replace newline characters in Java. Additionally, we will implement a custom JSTL tag so that we can replace newline characters with corresponding <br /> break lines within JSP files. Unlike PHP’s nl2br function, for instance, this is not as easy in JSTL. Replacing… read more

Selecting Elements by Data Attribute in jQuery

October 13, 2015 by

Selecting elements by data attributes is very easy in jQuery. As with all other attributes, we can simply use the attribute selector. In fact, we do not need to handle the data attribute in any special way, as long as the data attribute is available in the DOM. Please consider the following example. var matches… read more