Quick introduction to using Zend_Layout


Lately, the Zend_Layout component has been a very popular topic on #zftalk. It is indeed a very useful component, but a lot of people are having trouble understanding how it works.

Adding to the confusion is the outdated documentation regarding the component proposal and the equally outdated articles about Zend/Xend_Layout.

Let’s demonstrate the usage of the current Zend_Layout implementation, which can be found from the Zend Framework SVN or Snapshots in the Incubator directory.

Note: if you are using the Zend_Layout from 1.0.3, the stuff mentioned here will still work.

Zend Framework 1.5 users: there is an updated version of this article available here

Read More

Localize your site in 3 easy steps


Internationalization and localization means making your site usable in more than one languages. Well, to be honest, you could call a site that’s only in english localized to english visitors too, but in any case…

These two are also known as I18N and L10N. Can you guess where these acronyms come from? The first and last letter from each word and then the number of letters between… Someone’s been feeling really creative ;)

While PHP has an extension for GNU Gettext, which can be used for localization, it isn’t the easiest thing to use. Additionally, PHP can also do number and money formatting based on the locale, but this depends on the server: You must have the locale installed on it. On Shared Hosting accounts, some locales may be unavailable and you may not be able to install them. Not to mention that gettext can be a bit of a hassle to get working.

So, rather than using PHP’s native support, why not use Zend Framework’s Zend_Locale and Zend_Translate?

Read More

The mythical HTTP protocol


The HTTP protocol is what powers todays web. While not useful for most people, knowing how HTTP works is important for those who work with dynamic web sites.

Still, it seems that the protocol is mostly a mystery to a lot of developers and some features of the protocol, such as the accept-language header, aren’t really used.

Read More

Geek humor


Sunday morning, 5 AM…

– Hi
– Haven’t seen you in a while, but I have seen you in a foreach!

Proof against homosexuality: You can’t connect two male cable connectors.

note: I have nothing against sexual minorities, the above is just a funny fact ;) )

Camel-casing is fundamentally flawed

You know how camelCasingWorks, right? Well, I think it’s flawed.

Here is a camel
A camel

So, in fact, camelCasingNeedS to have the last letter in upper case!

Routing and complex URLs in Zend Framework


We were talking about routing on the #zftalk IRC channel. One of the users mentioned that rather than using routes, he was using the __call method in the IndexController.

I then asked him why is he doing that, as I knew routes would be more than a good choice for most kinds of URLs.

I found out that he was working with SEO and he was using a very interesting URL scheme: domain.com/productname-numbers-categoryname.html

This is actually quite interesting thing to think about. Not the SEO part, but how to make ZF understand these kind of URLs. The default routing in Zend Framework works very well for typical Zend’ish URLs like domain.com/hello/world/stuff/goes/here, but if you want to do some more specialized URLs, like the example here, you may need to do some thinking.

Because ZF is so flexible, I can think of four different ways to route complex URLs:

  • Using __call
  • Using a controller plugin
  • Using Zend_Controller_Router_Route_Regex
  • Customizing the Route class

These methods can be used for other things as SEO URLs as well, so let’s check out how to utilize these four and their pros and cons.

Read More

Zend Framework initialization shell scripts


I’ve had a couple of cases where I’ve wanted to quickly test some stuff with the Zend Framework. Now, to get the framework up and running, you’ll need a couple of things:

  • Directory structure – controller dirs, view dirs, public_html, etc. etc.
  • .htaccess files – To enable routing
  • Bootstrap
  • Controllers

I can never remember what to put in the .htaccess files and I often forget the parameters for the front controller in the bootstrap. But what if you could do all these steps with a single command?

I want to be able to run a single command and get the framework up and running without doing anything else.
So, I decided to whip up my trusty Vim and write a couple of shell scripts to do it!

Read More

How to improve your JavaScript


There’s a lot of resources on the internet related to coding JavaScript, but many of them are poor and out of date, which I believe is one of the reasons why a lot of people still can’t manage to write JavaScript code which works in all major browsers (IE, Firefox, Opera and Safari – where possible to test it)

Let’s check out some useful JavaScript resources to improve our skills, ranging from books to blogs and frameworks/libraries.

Read More

How to automatically escape template variables in Zend_View


Escaping any data which comes from the server is important to escape, as it prevents XSS amongst other things.

The Zend Framework view component Zend_View let’s you escape template variables with $this->escape($this->variableName), but it doesn’t escape them by default. Wouldn’t it be much nicer if it did that by default, or at least provided you with a variable to turn it on/off?

Let’s find out how to do that!

Read More

Summing up Smarty and Zend View


I’ve posted a couple of posts related to integrating Smarty with the Zend Framework:

  • Making a Smarty view class based on Zend_View
  • Integrating Zend View Helpers into Smarty

I’ve also posted some Zend_View related posts:

  • Using layouts with the Zend ViewRenderer helper
  • Creating a factory-object for building views

Let’s wrap up these in a summary of using them and what else could be done regarding these and the view solution in general.

Read More

Switching to WordPress


I’m moving my blogging from My Opera to here at CodeUtopia.net for now at least.

I’ve installed WordPress here, and I must say it was quite painless to get it up and running. I had to do some digging through the documentation to find some features that I want to use, such as showing a small “teaser” of the posts on the front page for some posts.

I was working on my own simple blogging solution and a CMS until an unfortunate hard disk crash took out my server box and along went most of my programming projects. And don’t tell me to take backups! I’m a poor student, I don’t have money for things like extra hard disks for backing up stuff ;)

Also, I have other things to work on than the blog/cms project, so I kind of realized that it would take me forever to move my blog here, unless I used a ready-made solution like WordPress.

I’ve imported some of my old posts to this one, but it looks like that many of them look a bit bad, especially for the parts which include source code of some sorts. I’ve fixed a couple of them to behave a bit better, though.

Read More