I wanted to add a quick post about this as it was something which took me a while to figure out and so I hope it will be helpful to others.

Sometimes in an app. you want a UIButton to be pressed and remain selected. Now you can set the selected property to YES
, but this doesn’t keep the appearance of a selected button.

Now you could make a custom image for your button and use :

[button setBackgroundImage:[UIImage imageNamed:@”someimage.png”] forState:UIControlStateSelected];

However I found this way of doing it to be better, particularly, as with most coders, if you’re not a great fan on photoshop.

first add #import <UIKit/UIKit.h>

We can then use the graphics layer to alter the buttons appearance. My thanks to http://cocoawithlove.com/ for pointing me in the right direction for this one:

- (void)controlButton:(UIButton *)sender

[[sender layer] setCornerRadius:8.0f];
[[sender layer] setMasksToBounds:YES];
[[sender layer] setBorderWidth:1.0f];

if (sender.selected == YES) {

[[sender layer] setBackgroundColor:[[UIColor lightGrayColor] CGColor]];

[[sender layer] setBackgroundColor:[UIColor whiteColor].CGColor];



Just wanted to add a quick tutorial on setting up PHPUnit on your mac.

First step:
Mac osX no longer comes with PEAR (PHP Extenstion Aplication Repository) installed and this is the easiest way, in my opinion to install and set up PHPUnit. So the the first step is to install PEAR

Open terminal and run:

curl http://pear.php.net/go-pear.phar > go-pear.php

next run the script

sudo php -q go-pear.php

You will next be given a list of options. The only one that needs to be changed is the install dir
set it to /usr/local

Press enter and it will finish installing PEAR. Next you will need to alter the php.ini file used by the default install of php on the mac. Run the following:

sudo cp /etc/php.ini.default /etc/php.ini

next we need to add the pear repo to the include path.

sudo nano /etc/php.ini
press ctrl w and type in include_path
change this from ;include_path = ".:/php/includes"
to include_path = ".:/php/includes:/usr/share/pear"
//restart apache
sudo apachectl restart

Now pear should be installed. So onto the PHPUnit.

sudo pear channel-discover pear.phpunit.de
sudo pear install phpunit/PHPUnit

And that should be PHPUnit installed. So now onto netbeans. Fire up netbeans and then open prefrences -> php-> general and set the php interpretor to /usr/bin/php then go to unit testing and add /usr/local/bin/phpunit as your phpunit script. You may also want to add to your include path in netbeans /usr/local/share/pear/PHPUnit this will enable netbeans to read the class files and prompt you with auto completes.

Hope this helped.

The Power of Zend_Validate and Zend_Filter

 Development, Zend Framework  Comments Off on The Power of Zend_Validate and Zend_Filter
Sep 062011

I don’t know about you, but I find that sometimes coding html forms and the corresponding backend validation to be the typical type of “Boiler Plate” code that once you’ve done it and understand the principles, that you never really want to have to do it again.

Into the breach steps Zend_Frameworks’ Zend_Validate and also Zend_Filter. This set of classes can be used in conjunction with the Zend_Form_Element Classes and Zend_Form Class and makes validating forms almost a pleasure. Let me show you an example.

Often with a web form we need to validate that an email address is valid. So you might use a function such as:

filter_var($email, FILTER_VALIDATE_EMAIL)

And then redirect back with an error stored in the user’s session if it fails. However it gets a little more tricky when you also need to validate that the email address is unique to your database table.

public function validateUsersEmail(){
if(filter_var($this->email, FILTER_VALIDATE_EMAIL)){
//do query to check email address not already entered
//if no return true
return false;

However Zend Framework offers a set of very powerful filters. which means you can create a form email like so from within a class extending Zend_Form:

$handleElement = new Zend_Form_Element_Text("handle");
//Here is where the validator kicks in
$handDbValidator = new Zend_Validate_Db_NoRecordExists('siteusers','handle');
$handDbValidator->setMessage("That username already exists");
->addFilter(new Zend_Filter_Alnum(false))
->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim());

Now that looks like a lot of code. However there are several validators and also filters being applied to this element.

Here is the code for checking if a record exists and also to set the error message to report to the user

$handDbValidator = new Zend_Validate_Db_NoRecordExists('siteusers','handle');
$handDbValidator->setMessage("That username already exists");

Here we specify the table name and the field name to check and then add an error message if it fails.

Now the filters

So how often have you gone searching for the right regular expression to strip out all none alpha numeric characters from a string? Well I know I often forget the exact syntax and go searching. Zend Framework offers you a great set of Filters to apply to your form elements. In the above code you can see them at work in the following way:

->addFilter(new Zend_Filter_Alnum(false))
->addFilter(new Zend_Filter_StripTags())

These are fairly self explanatory but show what is possible using the Zend_Form Class along with filters and validators.

You can find out more on validators and also Filters by following the links.

Locals.ie concept – hopes – and plan

 Ideas, startup stuff, thoughts and musings  Comments Off on Locals.ie concept – hopes – and plan
Sep 052011

So a while ago I wrote an article on scaling down. Where I spoke about the success of any individual being bound with the success of their community. Well at the time of writing, I was also, and still am, busy working on a new project. That project is locals.ie.

The Concept

The concept behind locals.ie is to provide a place for the locals in a community to easily talk about and promote what they love, hate, and want to change in their local community. This can be done in a number of ways on the site: you can add a post, ask questions which other locals can answer and also set up, manage, organise and promote local projects, whether they be their own or community based. I have lots more ideas planned and would love to hear any feed back positive or negative.


A major hope of mine is that first and formost that people find the site offers them something useful and worthwhile, but also that local authorities, tds, councilors, businesses etc catch on to the site and see its potential for connecting and communicating with the locals that make up their constituencies and communities.

My ideal, my dream, perhaps, is to have locals communicating with each other regularly and talking about what is on their minds. I also want those with ideas, perhaps ideas they have had for a long time, but have felt they didn’t know how to get started, or that they wouldn’t be listened to, find others who share in their idea and so do more than get started, they actually make things happen; and for those with valuable local knowledge to share it by adding posts and answering the questions asked by others.

You can see a good example of how the site can work by taking a look at the waterford section of the site. This is my home county.


Over the coming months I am going to be working hard to try and promote locals.ie in anyway that I can. I plan on writing to my local newspapers, perhaps submitting an editorial piece to them, and also contacting radio stations to try and gain some exposure. I also want to get in contact with my local council, politicians and businesses.

I will also be working hard on the site. I hope to improve it with each day/week and make it a great place to visit. If you have any ideas or thoughts on locals.ie please don’t hesitate to contact me. You can use this blog, or via email at craig[at]locals.ie you can also follow @locals_ie

I am a web and software developer by trade and so have plans to bring out a mobile app in the future at some point also.

If you like the idea of locals: tweet about it, like it on facebook, talk about it, but most of all become a local and get involved.

© 2012 Craig Brookes Suffusion theme by Sayontan Sinha