Google analytics code

Tuesday, April 22, 2014

Zend Framework 2 & MAMP : Memory Issues

I ran into a problem working through the tutorial for Learn ZF2 for form validation. I reached the section where the form data would be inserted into a database and that wasn't possible using the command line PHP server. I decided to switch to MAMP because it has more stuff baked in.

I quickly ran into an issue that was tough to track down. After added the database code the form no longer submitted. After ripping out lots of code and not finding an answer I called it a night. The next day I figured out the problem was with MAMP not my code. If I disabled the file validation on the form everything worked fine.

This was the error I ran into
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 32 bytes) in /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/Stdlib/ErrorHandler.php on line 113

Not the most straight forward bug. Turns out the issue is the command line PHP server has a larger memory_limit size. It's 128M while MAMP is set to 32M. It overflowed after processing the file. After upping memory_limit to 128M and restarting the server everything worked fine.

The memory_limit var is stored in php.ini. It can be reached by using
File => Edit template => php => php 5.4
Find memory_limit and change it to 128M.

Wednesday, April 9, 2014

Zend Framework 2.x Learn ZF2 by Example : Unable to render template

Getting to the MVC portion of the book and ran into an error. On page 59 it shows you how to manually include a template to aid debugging. I ran into this error when trying to see my changes.


Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "debug/layout/sidebar"; resolver could not resolve to a file' in /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:498 Stack trace: #0 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/View/View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel)) #1 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel)) #2 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent)) #3 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent)) #4 /Volumes/zend_framework/learnzf2/vendor/zendframe in /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php on line 498

Page 58 talks about the way templates are included. The middle of the page shows a config option called 'template_path_stack'. This is the path the PhpRender uses to find manually included templates. There is a similar line in the Application module.config.php. I thought this would be imported into the master config but that didn't happen. You have to add this.

Tuesday, April 8, 2014

Zend Framework 2.x Learn ZF2 by Example : Error creating Debug module

I'm rewriting part of my website with Zend Framework 2 because I want to use something more mature and flexible than something I wrote years ago. I picked up the book Learn ZF2 by Example because it was rated well. The intro gets your feet wet and eases you in. I got stuck when trying to reproduce the steps to create a new module using ZFTool.

On page 28 under Automatic Module Creation they want you to download a tool that will help with creating new modules. I'm not sure if the instructions are old but it not work. Running the command will give you the following error

Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:189
Stack trace:
#0 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(163): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZFTool')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/ in /Volumes/zend_framework/learnzf2/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 189

Your path will vary, but the error is the same. Searching google didn't give me a good answer. The ZFTool page has instructions on how to install the it using composer. When the install finished I ran the command php vendor/bin/zf.php create module Debug and the new module was created.

I hope this saves you some time.