Day number two of porting this application to zend framework 2. I only had a couple of hours today but still i have a couple of things i actually want to talk about. I keep encountering things that are not that much different from ZF1 like Zend\Navigation or Zend\Paginator. I was quite surprised i got them working in seconds.
In the app i have a paginated list of documents, and below is how the code changed:
Zend Framework 1
$db = Zend_Db_Table_Abstract::getDefaultAdapter(); $select = $db->select()->from('document', $orders)->order(array("$order $way")); $paginator = Zend_Paginator::factory($select); $paginator->setDefaultItemCountPerPage($perpage); $paginator->setCurrentPageNumber($this->_getParam('page'));
Zend Framework 2
$db = $this->getServiceLocator()->get('db'); $select = new Select('document'); $select->columns($orders)->order("$order $way"); $paginator = new Paginator(new DbSelect($select, $db)); $paginator->setDefaultItemCountPerPage($perpage); $paginator->setCurrentPageNumber($page);
Which if you exclude all the Use Statements you have to add on top it's not bad, i actually think it pretty much the same. It would be nice to be able to get the Select object from the adapter but it's not a big deal. The second thing of the day was how actively the ZF2 is developed. I found a couple bugs today working with v2.0.3. The most important was with the Zend\Mvc\Router\Http\Query which was adding the controller, action and namespace parameters to the query string, instead of only adding the extra parameters it was receiving. But guess what download the latest version from github and voila bugs are gone. (Lithium are you there... ;p). That really made my day, i make it a habit not following popular trends or rooting for the underdogs, see my history. I started learning php with LDU cms probably the most unkown cms of all and now choosing Lithium for Komposta Core instead of one of the most popular frameworks like Zend or Symphone or CakePHP for pete sake. So it felt great to go from the disappointing moment of finding a bug to see that i was fixed in a minute. People are whining how much ZF2 changed and that it got a bit Java-ish but today at least, in my mind ZF2 will succeed because of the active developers and contributors.