In a very old post I told you how to get the route name in custom view helper with zf2 – Zend Framework 2. In this post I used the ServiceLocator, a thing which was some kind of deprecated in later versions of zf2. It is bad practice to use such a construct like the getServiceLocator method, because e.g. applications …
Doctrine with zf3 cache
That’s the way how to use Zend Cache with Doctrine in Zend Framework 3. First do all doctrine settings and define a cache in your global.php: ‘doctrine’ => [ ‘connection’ => [ // default connection name ‘orm_default’ => [ ‘driverClass’ => ‘Doctrine\DBAL\Driver\PDOMySql\Driver’, ‘params’ => [ ‘host’ => ‘localhost’, ‘port’ => 3306, ‘user’ => ‘xxx’, ‘password’ => ‘xxx’, ‘dbname’ => ‘xxx’, …
zf2 – translatePlural example with Poedit
I’d like to explain how to use the translatePlural method along with the Zend Framework 2. (I’m assuming that you have been configured Poedit and the Zend Framework so that it works with the normal translate method) The use of translatePlural is actually quite simple. Let us first look at the normal translate method: [php] echo $this->translate(‘example.key’); [/php] After parsing …
Subdomain based mobile versions in zf2 projects
A few weeks ago it was my job to extend an existing Zend Framework 2 project with a mobile version. The orderer wanted when calling mobile.example.com/path1 a for mobile clients optimized version of www.example.com/path1 should be delivered. Some mobile versions of pages should have only a changed layout, while others should provide additional content. These requirements (for requests with the …
zf2 – logger problems with the FirePhp/FireBug writer in a console request
In my recent zf2 (zend framework 2.1) project module I defined a logger with a stream writer and a firephp writer. I am using the same module also for some console requests (Zend\Console). The problem I had was that the system complains of the firephp logger when I did a console request: [plain] ====================================================================== The application has thrown an exception! …
zf2 – Get the route name in a custom view helper
======================== IMPORTANT UPDATE: this is a very old post – find a better way in my post “zf2/zf3 – get the route name in a custom view helper” ======================== Ever tried to get the route name in your custom view helper in a zf2 (zend framework 2.1) project? I searched a lot – until I realized that I have …
zf2, doctrine module and expressions (like ‘IS NOT NULL’)
Currently I am working on a migration of a zend framework 1 project to zf2 (zend framework 2). Furthermore I want to introduce Doctrine to the project. There are some useful articles about installing and using the zf2 doctrine module. After some hours I found out how to use modules and Doctrine in zf2. Sometimes you will have code like …
Zend_Captcha, an example without Zend_Form
Here is your example how to implement Zend_Captcha_Image without using Zend_Form. In your action method: [php]public function indexAction() { //… $captcha = new Zend_Captcha_Image(); $captcha->setImgDir(APPLICATION_PATH . ‘/../public/tmp/captcha/’); $captcha->setImgUrl($this->view->baseUrl(‘/tmp/captcha/’)); $captcha->setFont(APPLICATION_PATH . ‘/fonts/elephant.ttf’); $captcha->setWidth(350); $captcha->setHeight(150); $captcha->setWordlen(5); $captcha->setFontSize(70); $captcha->setLineNoiseLevel(3); $captcha->generate(); $this->view->captcha = $captcha; // giving captcha object to the view //… }[/php] In the corresponding view render the captcha and add a hidden …
Client localisation with zend framework
If you want to find out the language or country of the clients browser, do it this way: [php]<?php require_once ‘Zend/Locale.php’; $locale = new Zend_Locale(); echo $locale->toString(); ?>[/php] But be aware! This way you only get the localisation of the clients browser. And this is configurable by the user. The code above will give you output like this: [text]de_AT[/text] or …