Zend Translate Plurals
I know it should be pretty common sense to RTFM - but sometimes you miss things.
These blog entries are about the Zend Framework so they’re tagged with “zend-framework” - however, this project is now called Laminas.
I know it should be pretty common sense to RTFM - but sometimes you miss things.
Perhaps this trend is going away, but it used to be a “good thing” to make people validate their passwords. I did all kinds of silly things in Zend Framework Form and jQuery Validate plugin at first - but then I finally settled on a good solution. It’s quite simple actually…
One of the worst things with CAPTCHAs are actually having to solve them. One of the things my team and I use for our projects is the hidden field CAPTCHA. This is a technique that adds a field to a form, but uses CSS to hide it. If that form value is filled in, we can guess that the submitter was a bot reading the HTML - and not an actual user.
To start out, I realize that a lot has changed in Zend Framework 2 regarding Zend_Form. I think there have been a number of interesting changes, but perhaps those changes weren’t explained that clearly either. But I digress. This piece is about Zend Framework 1.12.x Zend Form - and using view scripts for elements/the form.
This is a weird one… I had a form in the body of my page. Every time I would submit it, the csrf token would not match.
So one of the things that really bothered me about the Zend ACL implementation in 1.x was the inherits()
method. It simply would test to see if the current role inherited the roles you were testing against. Well, what if the role WAS the tested role? Then it would fail. So, to fix that, in my own Application_Model_Acl
implementation, I wrote inheritsIncluding()
.
By default, the labels of form elements in Zend Form are escaped. Sometimes, like in check mark boxes for Terms of Use, it makes sense to add some HTML to this. You can turn off escaping - but just be careful!
For the most part, ZF can capture any of your hard errors. It will generate an error 500. You’ve seen them, don’t lie… I’ve seen them way too many times. However, in my production application, I capture these with a specific controller. And because I love Unit Testing, I want to make sure that I test my implementation of my omg-this-is-broken setup.
There are two areas where user input should be filtered: on display and on storage. Luckily, Zend Framework provides tools for this…
So, since I want to save some keystrokes, I rarely will go back to the Front Controller and Bootstrap to get resources. I also like to store them in the registry in a fashion that I see fit.
I’ve been making a push to have more of my projects multi-lingual. However, one thing I kept forgetting about was those super-rare error messages that have to come from the Controller. For the most part, all of your errors should be handled by your validators in your forms. However, from time to time, there needs to be an error handled in your controller.
I love working in the Zend Framework view system. One thing that bothers me, however, is that I must create a complex set of models when trying to send email. I decided that I’d like to move all of this output for the mail class into my own view system as well.
Have you ever used Zend Form, created a submit button, and had a few extra tags that were just throwing you off? I know you have… You probably did it like me:
By default, when using the Zend Paginator, the result set will come back as an array. If you are using a paginator associated with a database result set, and that db has a class defined for its row, it will come back as that class. However, if this is not the case, or you are not using information from a database, you may still want a different result than just a plain array.
It drives me nuts that the best practices with javascript that is not required for the initial rendering of your application is to be placed at the bottom of the document, yet frameworks (like Zend Framework) do not support that out of the box. (I recently found out that Joomla also shares this problem.)
I’m no sys admin, so I can’t be sure, but I’ve seen lots of issues with using things like MySQL Proxy to fully separate the write and read queries in an application. Maybe it works, I don’t know… but I do know that if I can separate the connections in my code, that saves my Admin time… it doesn’t appear to give that much of a hit to performance either! Do keep in mind that this is only working at the table level in Zend Framework. If you use their database system, this should do the trick. If you do a lot of getting the adapter yourself, this won’t help you at all!
For a CMS I’ve been working on, there are a number of custom routes that are added statically in a loop. These point to specific ID’s of articles on on the default module’s page viewing controller/action. Sometimes these routes need to appear in the Zend_Navigation
output. As you can probably guess, the logic used for this is similar to what you might experience when using the URL view helper. But, for some reason, I could never get the URL’s to be marked as active.
One of the things that is irritating is logging into a website with credentials that you know are right, only to have it fail. Then, later, you find that the site was malfunctioning. By then, maybe you requested a new password, or had to at least waste time looking up your old password. With Zend_Auth
, however, we can prevent user’s from having that issue.
There has been a lot of discussion on forums and throughout the object oriented PHP programming community about service classes. This is just intensified by the Zend Framework model of development coupled with the changes in their design/architecture and vocal spokespeople. I thought I’d throw my hat in the ring for this.
This article is the follow-up to the original article
There was some discussion on Twitter regarding the original version of my article about putting most of your site’s setup in the front controller plugins in Zend Framework.
I was creating a new application with Zend Framework at work the other day and I started using my technique that I described here by adding the original email in my email address using the + sign. However, the current organization I’m at has a mailserver (Exchange?) that is either configured not to allow this or just doesn’t have this functionality built in. So, this won’t work. I solved this with a new implementation of the mail class.
Thanks to Zend and their community organizers for the opportunity to do a webinar today.
All the examples I’ve seen for pulling information from subdomains are from the hostname router directly correlating one subdomain as a value to a single controller/action combo. This means they map username.website.com to something that basically looks internally like website.com/user/profile/var1/username
. This is cool for simple one off tasks - however, what if you’re creating a multiple controller/action solution? For my example, I’m creating a CMS that will have a shared code base. However, on every page, I need to know exactly which site this is.
There are two ways of working with Zend Framework as a library in your project. These are including it in your project repository and using a shared copy on the server (like PEAR). Let us discuss both:
For some reason, I just had the most horrible time making sure that my connection from my Zend Framework code was speaking UTF8 at my database. Here are the key things to remember that I learned:
Zend Framework has a few hooks with the Firebug browser plugin (with the FirePHP add-on). The two that I use are writing logs to the console and profiling of database connections.
Through reading a few blog posts over the last year and my own trial and error, I’ve developed a way of using the flashMessenger
Helper in ZF that works out really well for me. (Note: if anyone knows the original blog post that I got some of the view helper from, please comment!).
Google Charts has a QR code generation service (here are the details). I decided that I wanted to create my own ZF View Helper to display these on my pages. This version that I am going to show just returns the properly formatted URL for the charts API. The view must create the img tag around it.
Running a test, I ran into this error:
Today I was reviewing some old code I wrote in Zend Framework. One of the things I was doing in the Bootstrap.php
file was creating an function called _initViewSettings()
. In here I set a bunch of values for the xhtml version, the css files to include, etc. Now I realize my mistake:
Theme systems are very common in projects written on Drupal, Joomla, and Wordpress. I didn’t see much out of the box support for themes in Zend Framework at first. However, I was wrong. It’s pretty easy. The only real decision I had to make is if I want to make themes that extend a default theme - or themes that are simple and on their own / totally encapsulated. I will do the encapsulated version - but give some pointers on how you would do the other version, too!
I’ve been using Zend_db
to create a query which does a simple search on three columns of a table. Fortunately, I found out that the where()
statement handles single parameters intelligently when there are multiple placeholders. In the case that there are many placeholders but only one parameter, that parameter will be added to each of the placeholders the same.