Beginning Zend Framework by Armando Padilla

24th April 2011 - 4 minutes read time

Beginning Zend Framework

I was lucky enough to pick up a couple of free books from the recent PHP Unconference Europe, one of which was Beginning Zend Framework by Armando Padilla. Having not looked into Zend Framework for a while I thought I would read the book to refresh my knowledge catch up and post a review.

The premise of the book was to create a sample application to keep track of music artist information, with each chapter building on the code from the previous. The first few chapters are about installing Apache, PHP and MySQL and some UML diagrams of the application that will be built. After reading this I was actually enthusiastic about the application and couldn't wait to get started.

PHP Logo

PHP Question: Form Variables

22nd April 2011 - 4 minutes read time

Question

Given the following form:

  1. <form method="post" action="index.php">
  2. <input type="input" value="" name="text" />
  3. <input type="submit" value="Submit" />
  4. </form>

How would you get hold of the value of the input box after the form is submitted?

Drupal Logo

Creating Custom Views Filters With An Exposed Form Element In Drupal 6

20th April 2011 - 5 minutes read time

Views is an amazing module, but sometimes you can come across certain limitations that make life difficult. For example, I created a view that pulled in a bunch of nodes based on different taxonomy terms. The problem was that I had more than one taxonomy term in different vocabularies being used to filter the results, which essentially caused the same field in the term_data table to be used for both taxonomy filters. So, no matter what I changed the parameters to I always received no results. I did try and add the second term as an argument but it isn't possible to do LIKE matches with views arguments.

PHP Logo

PHP Question: Pass By Reference

19th April 2011 - 2 minutes read time

Question

Consider the following:

  1. function doSomething(&$val) {
  2. $val++;
  3. }
  4.  
  5. $a = 1;
  6. doSomething($a);

What does the variable $a now equal?

PHP Logo

Number Pair Additions In PHP

16th April 2011 - 4 minutes read time

I was helping my son out with his maths homework today and we came across a question that asked him to find some combinations of two numbers that added up to a given number (he is only 6 so this was good maths practice). This got me to thinking about how to calculate all possible ways in which two numbers could be added together to make another number.

The only rule had to be in there was that doing things like 1+11=12 and 11+1=12 are basically the same thing and so would be cheating. In which case I realised that it would only be necessary to use half of the numbers when creating the list, so for the number 12 every combination can be found using the numbers 0-6 because after this we start duplicating the sums, just swapping the order.

Here is the function I came up with.

PHP Logo

PHP Question: Octal Values

15th April 2011 - 1 minute read time

Question

If I assign and print a value like this:

  1. $a = 012;
  2. print $a;

I get back a value of '10', why?

Drupal Logo

Automatically Copying The Node Title To The Menu Title In Drupal 6

13th April 2011 - 3 minutes read time

One new feature of Drupal 7 is that any title you give a node will be copied to the menu title field when you create a menu item. I wanted to replicate this functionality in Drupal 6 and so I created a function that did just that. I have used this function a few times in different projects so I'm posting it here.

This code uses the drupal_add_js() function to push a small amount of JavaScript code into the page when a node is added or edited. The hook hook_init() is used to add this content as it is run very early on in the Drupal boot cycle. I have tried putting this code into other hooks (like hook_preprocess_page()) but it isn't included, I would look into this further but this solution seems to work well.

PHP Logo

PHP Question: Increment By One

11th April 2011 - 2 minutes read time

Question

What will the following snippet print, and why?

  1. $count = 0;
  2. print $count++;