Code Migration to iOS 5
by Dale on Sep.13, 2011, under General
If like me you decide to migrate some of your existing code over to iOS 5 you might find that you have a ton of errors thrown up regards to the releasing of objects. The reason for this is the new Automatic Reference counting in iOS 5, it’s there as Objective-C’s version of garbage collection.
To get over these errors without having to migrate your code over to accommodate the new reference counting you can turn it off entirely. This will mean that you cant use the reference counting throughout the rest of your app, but to just get things working quickly this is a good solution.
Click on your project in the ‘Project Navigator‘, from here look at your main pane and you will see some tabs at the top, one will be labeled ‘Build Settings‘, click on this and then click on the ‘All‘ button just underneath to show all of the options. Now scroll down the list (or type in search) until you find the option called ‘Objective-C Automatic Reference Counting‘, change it’s value to ‘No‘.
This should sort out the basic problems with migrating your code over to iOS 5, but remember to get around to migrating it fully across in the future so you can take full advantage of the ARC features.
CodeIgniter – Basic Site Templating
by Dale on Sep.08, 2011, under General
There are several tutorials already floating around the web on this subject, but I decided I would tackle my own version, you know, just because I can.
1) First things first, lets start with a clean copy of CodeIgniter, either run it locally using XAMPP or upload the files to your web host, it’s entirely up to you.
2) Right, now your have CodeIgniter setup, head on into the application > controllers folder & open up ‘welcome.php‘. The objective of a template is to make it simple to load exactly what you want, so all we want to do here is send the name of the page we want to a view & it should load that page for us. To do this go into the ‘index‘ function & remove whats already in there so we start with a clean sheet. Now add the following into the ‘index‘ function:
$data = array ('page' => 'home');
This is the array we will be sending to the view, you should be able to see that we have filled it with a single value detailing that the page we want to load will be the ‘home’ page. This array can be filled with as much information as you want a view to have available like a users name, or some kind of dynamic information you want to be made available. Next we want to load a view & send our array of information to that view, to do that we can write the following line:
$this->load->view('template', $data);
At the moment we dont have a view named ‘template‘ so if you tried to access the index page of your website you would get an error, but we will soon sort that little problem.
3) Now it’s time to create the basic template view! Head down to the application > views folder and delete ‘welcome.php‘, then create a new file called ‘template.php‘ & open it in your favorite text editor. To begin with we will add the basic HTML that every page needs:
<!DOCTYPE html> <html lang="en"> <head> </head> <body> </body> </html>
4) Now we have created the basic structure of our web page we need to start filling it in. Firstly we want to create a new folder to put all the standard bits of our web page into, so in the application > views folder, create a new folder and call it ‘std’ (short for standard), or whatever you feel most comfortable with. Into this folder create a new file and call it ‘head.php‘, & within this file we will put all of the standard head information like what scripts we are going to be loading, the meta data etc. You can also add files to tackle the tasks of menus, footers and such into this folder, but I’ll just be concentrating on the basics for this post.
<!-- Title --> <title>My Awesome Web Page!</title> <!-- Meta Tags --> <meta charset="UTF-8" /> <meta name="description" content="An awesome web page about me!" /> <!-- Favicon --> <link href="<? echo base_url(); ?>images/favicon.ico" type="image/x-icon" rel="shortcut icon"> <!-- Style Sheets --> <link href="<? echo base_url(); ?>css/style.css" type="text/css" rel="stylesheet">
You might have noticed that I have added a few little extra’s that wont be talked about as you should know enough HTML to work them out on your own, if it’s a little confusing then you should go and learn a little bit about HTML first & then come back. One thing I will point out is the use of ‘<? echo base_url(); ?>‘, all this does is grab the root address of the web page & makes sure that if you do move the site at any point to another address you wont break the links.
We could enhance the <title> a little bit by adding the page name to it. To do that we want to pull up the information sent by the controller to the template view & just add that to the existing text for the title. Here is a little taster on how to do that:
<title>My Awesome <?(isset($page) ? echo $page : echo "Web");?> Page!</title>
A quick shorthand if statement will add the page name to the title, if there isn’t a page name to add it will just echo “Web” instead to go back to the default title.
5) The next step is to create another new folder in application > views, call this folder ‘pages‘. In the pages folder create a new file called ‘home.php‘, make sure it’s the same name as the page you are trying to load with the template. In this file add something very simple like my example below.
<p>This is my home page!</p>
6) We now have everything setup so head back to the ‘template.php‘ file in the application > views folder. The final task we want to do is to load these files in to the template, to do this we will use the $this->load->view() function again. Within the <head></head> tags add the following line:
<head>
<? $this->load->view('std/head'); ?>
</head>
This will load the head information that we added to ‘head.php‘. Next we need to load up the page that we originally asked for in the welcome controller, to do this add the following code to ‘template.php‘ within the <html></html> tags.
<html>
<?
if (isset($page))
{
$this->load->view('pages/' . $page);
}
else
{
?><p>Page Doesn't Exist :(</p><?
}
?>
</html>
The above code will check if the page name ($page) has been passed to the view and attempt to load that page, if the page name hasn’t been passed to the view it will display “Page Doesn’t Exist :(“. Save all of the files we have edited and load up the web page in your favorite browser & if all things have been done correctly you should see yours home page loaded up along with the correct page title that was set in your head information.
This is just the very basics of template creation with CodeIgniter, it can be expanded as much as you like into something very complex, you can create a lot of standard items and load them as and when you want depending on the values passed from the controller. I hope this gives you a better understanding of template creation with codeigniter & allows you to go on to create your own complex templates for your websites.
CodeIgniter – Using AJAX with CSRF Enabled
by Dale on Sep.06, 2011, under CodeIgniter, Development, General, Tips
One problem that I came across early on with CodeIgniter was the ability to use AJAX while using the CSRF security features that are built in to the framework. Initially I didn’t realize what was going on as I had just enabled all security security features by default & didn’t realize it was the CSRF (Cross-site request forgery) that was causing the problem, all that was getting returned from any AJAX call was the following error:
An Error Was Encountered
The action you have requested is not allowed.
After fiddling around with several things to make sure my AJAX calls through jQuery were working correctly, I went to Google and found out that it was the CSRF causing my problems. The problem was that all of the solutions that I found to fix the problem were all very hacky solutions that meant changing the way the CSRF functions which wasn’t ideal. So, off I went to do a little bit of digging to see if I could find another solution myself that was less hacky and didn’t change the way the CSRF functions. A solution was found & I have now detailed it below.
First things first, make sure you have CSRF enabled in application > config > config.php & make a note of the ‘csrf_token_name’. The token is used to validate the form & is an essential part of the CSRF protection process, it’s also at the core of the problems I encountered.
$config['csrf_protection'] = TRUE; $config['csrf_token_name'] = 'cc_csrf_token';
Now, when creating a form make sure to use the ‘form_open()‘ function from the form helper, this will insert the hidden CSRF token into your form without you having to do anything else. You can check this by looking at the generated source of the page where the form is located and just underneath the <form> tag you will find the token field.
The first thing that you need to do when you are sending anything by AJAX is to pull the data out from the form you are using with JavaScript & compile it into a nice string to send to the server. This is nice & simple with jQuery, all you need is the ‘id‘ of the input filed & the ‘.val()‘ function, compile them into an array & away you go. This is all well & good, but when using CSRF, CodeIgniter looks for the token to validate any incoming information, so unless you also send the token in your AJAX data you are going to hit the problems that I came across & get an error.
To pull the token from the hidden field you need to use the ‘name‘ attribute as there is no ‘id‘. You can do this using jQuery by writing the following:
$('<strong>input[name=cc_csrf_token]</strong>').val();
Now we have the token we can simply attach it to the rest of the form data and send it via AJAX. Hey presto everything should work again due to this simple solution with no hacky procedures!
Here is my final AJAX code using jQuery:
$('#submit').click(function()
{
/* Compile Data */
var formData= {
cc_csrf_token: $('input[name=cc_csrf_token]').val(),
email: $('#email').val(),
phoneNumber: $('#phoneNumber').val(),
content: $('#content').val()
};
/* Send Data via Ajax */
$.ajax(
{
type: "POST",
url: "<?=base_url();?>email/send",
data: formData,
success: function(msg)
{
alert(msg);
},
error: function(msg)
{
alert('Error: ' + msg);
}
});
/* Stop Page Linking to form submission target */
return false;
});
Lyndale Interactive Brochure
by Dale on Sep.01, 2011, under iPhone, Portfolio
I will continue the structure that I started with the previous apps to keep things neat and tidy. Here is an app that I quite enjoyed doing, mostly just because it didn’t have to connect to the internet which makes a change. It was developed in the latter part of 2010 during a slow week at work, it’s not quite as I would like it but other work called and it was ok enough to just get out of the door so we just published it as it was.
Overview
This app is an interactive brochure for a staircase company to demonstrate it’s products & past work. The app includes a stair parts explorer with suggested parts matching, studio photo’s and fitted photo’s. It also includes a simple Rise/Go calculator to help the user work out the number of treads they need on their staircase and also a contacts page which includes a variety of interactive ways to contact the company.
Technical Bits
There are no real technical parts to this app, mostly uses simple core animation and standard objective-c.
Screen Shots

Parts Matching Example
More Information
www.lyndalestairs.co.uk
Neglect
by Dale on Sep.01, 2011, under General
So to tell you the truth I’ve pretty much ignored the front of my website since my last posting on it, the site doesn’t get many hits and to tell you the truth I wouldn’t have even started to look into doing anything with it unless it was for the fact I’m now job hunting. “What do you use the site for then?” you may ask yourself, well I mostly use it for development tasks, experiments, hosting friends websites and odd jobs where it’s easier to access the internet than to send a large file via e-mail etc.
My plan now is to use this blog for it’s initial purpose, which is posting about projects that I’ve done or I’m working on and my experimentation’s with various technologies and such. Hopefully this way it’ll give any future employer an idea of my work and give them more of an incentive to hire me… or chuck my CV in the bin, who knows! The final thing I want to say before this ‘saying sorry to my website, but promises to be kinder in future‘ post is what technologies I’m currently experimenting with, or have touched and fallen in love with since my initial posts all that time ago.
Codeigniter is a big one for me, oh codeigniter, how I love you so! Codeigniter is a PHP framework that makes structuring your web applications and annoying repetative repetitive tasks quick, simple and easy. It’s very simple to learn and has a giant collection of modules for a number of different tasks from database query’s to shopping cart management, & if you find there isn’t a module to do a task for you, it’s extremely simple to create & implement your own. The documentation is brilliant, I haven’t had to touch the forums once for help, but if you do get stuck the community seems to be very helpful. Since I found out about codeigniter all my new projects have started with it & I’ve migrated a couple of current projects across to it with very little difficulty. All in all, codeigniter is a recommendation I would make to any PHP developer.
Processing.js is a new one to me, I’ve only touched a little bit so far and was recommended it by a friend, so onto explaining what it is! It’s a powerful platform for HTML5 canvas development, it aids in the drawing and animation to the canvas element kind of like flash, but works on mobile devices. You can either use JavaScript or a Java like language to develop your creations, and so far it’s been pretty easy to create anything I’ve wanted to. It would take an experienced JavaScript developer 10-15 minutes reading to get the basics down and from then on it’s all about experimentation with the simple to use references on the website. The documentation doesn’t go into massive depths, but there are plenty of examples available which demonstrate all of the features of the platform.
The other things that I’ve been enjoying is playing around with are the new storyboarding features in xCode for iOS5 which are brilliant for demonstrating to clients how their app is structured, and UDK, just for when I’m bored.
Right, now it’s time for some real posts!
iTIP Football 1.2
by Dale on Nov.29, 2010, under General, iPhone, Portfolio
Overview
This is another update to iTIP Football which works more on the back-end of the app rather than many feature improvements within the app itself.
Technical Bits
This update includes an entirely new back-end to the app to allow for user accounts and in-app purchases. The new back-end was created with a module design in mind to make updates easier and quicker to implement. A bunch of additional server features were added which include high server load detection, the ability to put the server into maintenance mode to only allow admins to access the server during backups and updates, better server reports, user access levels, better server control and many tweaks and performance improvements.
The app has also had it’s back-end re-written to accommodate the new server software and has had the addition of an login and account page. A few bugs have been fixed and there have been some slight UI changes to give the UI into a bit more uniformity.
More Information
iTIP Football
by Dale on Aug.18, 2010, under General, iPhone, Portfolio
I will start this blog detailing my latest creation; iTIP Football.
Overview
I was commissioned by the good people at iTIP Interactive at the beginning of the year to create an iPhone app to provide a football betting tips service. The app provides match preview analysis and a number of betting tips each week for a variety of matches in the English Premier League. It is a subscription based service that allows the user to buy as much or as little service time that they want.
Technical Bits
The app is iOS 4 enabled and provides high resolution graphics for the iPhone 4′s retina display. It automatically downloads all of the latest data upon loading the app and continues to keep up to date with the latest data while in use and refreshes any data accordingly.
The app uses a php based web server to provide data at the app’s request. The server manages all account based subscription services, news listings and match/tip information automatically. The server has it’s own web based administration front end that provides the content providers with the ability to add and administer content provided on the app as they see fit.
Screen Shots
More Information

