PHP
The context of this is actually for ACL, where I wanted to determine whether a use can view the link or not. I have seen other people extend the URL View Helper to do this which kind of works, but it just means the entire <a> tag has to be produced by the helper rather than the URL. This didn’t sit too well with me, so I settled for wrapping the <a> in a IF block. Within my templates I only use the route name, i don’t pass through the module/controller/action params to the URL helper, as it means refactoring modules and controllers is much easier, if the need were to arise. Due to this, I needed to fetch the Module name, Controller Name and Action name from the Route name. Simple eh?
Continue reading “Zend Framework – Get The Module, Controller and Action by Route Name” »
When using technologies such as Zend Framework and Doctrine, some form of OpCode caching is a must. The average memory used per request with Zend Framework alone is ~30MB, which is a massive performance hit. Doctrine doesn’t fare much better either. My prefered caching mechanism is APC, but there are certain conflicts it has creates when using it with these technologies.
Zend Translate is a great piece of kit, allowing you to switch between translation adapters with the flick of a few keys. GetText is my sin of choice, and that is what I’ll be talking about here. GetText itself can scan over projects and pick up all the translations, and drop them into your PO files. This is fantastic, as long as you stick to the extremely strict methods that GetText defines. But if I’m using Smarty translation blocks, how do I get GetText to pick them up? Because am I hell adding them all in by hand!
Continue reading “Zend Framework – GetText, Smarty and Automatically Adding The Translations” »
Sounds easy enough really, or it should be anyway! When using a routes.ini with the Zend_Router, the concept is you only ever refer to the name of the route, rather than the URL itself. So if you have an awkward client that suddenly wants a URL changed on their website because their “SEO Expert” thought it might be a good idea, you simply change the url against that Route name, and the whole website updates to use this URL. Better than spending several hours going through every page on the website and updating each link manually!
I’ve recently had a couple of requests for an example project using Zend ACL, so I thought I’d set one up really quickly. I have to say that a lot of credit goes to Dave Clarke who implemented most of the code here at work for our current project. Hopefully this short description, and the example install should help a few people out who are struggling with this largly undocumented ACL-shaped beast.
Doctrine is a fantastic ORM, and it is my preference when developing any large scale PHP application. However it has some holes in the documentation that catch me, and I assume many others, out every so often. One of these little hick-ups in the documentaiton came when a colleague and I were attempting to do a deep copy or clone of a doctrine record with its loaded relationships. Simple according the documentation.
Continue reading “Doctrine – Deep Copying of Relationships” »
A common technique I use in PHP is to cycle an array and remove the array items which aren’t required for my operation. For instance if I’ve got an array of questions, and I need to remove all the questions that are already answered, as well as removing the questions that have been disabled or are irrelivent for that user, I will go through the question array and unset() the array item. This will leave me an array with only the required questions. Simple enough really, but a side effect of this is that all of the array keys are now foobar’d, so we will need to rebuild the array keys.
Today I was passed an article entitled CSS: CamelCase Seriously Sucks! by Harry Roberts, by the front-end developer at work. You guessed it, the article was about CSS Naming Conventions. And it also doesn’t take a genius to work out that Harry Roberts isn’t a massive fan of CamelCase. A summary of his article is that as CSS uses a hyphenated delimiter for all its properties (eg background-color, z-index) you should name your CSS elements in the same hyphenated system. This is a valid point, and at first glance is very logical. However, if you take a step back it might not actually be that practical.
This is something I do quite frequently, normally for AJAX actions that don’t require a template to be rendered on completion. It seems a little pointless creating a blank template just to honor Zend Frameworks proccess of every controller action linking to a template file. Its even worse adding in a die() or exit(), as this completely disrupts the flow of the code. The right way to do it is to simply disable these features, and stop Zend Framework trying to render the templates.
Continue reading “Zend Framework Disable Template Renders” »
Recently at work we came across an issue using Zend Frameworks Form builder – Zend Form. We were creating a form which contained a checkbox and this checkbox had to be checked for the form to be valid. In other words, if the checkbox wasn’t checked, the form should fail validation. Simple Eh?
