Friday, 22 June 2012

Zend/Zend tutorial review


Zend seems to be a pretty good framework, as one would expect. From what I have seen, most of the code seems clean and logical. It has useful built in scripts to call to set up basic files. Seeing as developers are lazy, it's nice to have code to write your code for you.

There are some things that I'm not keen on. It seems to be that forms seem to post the data back to the same page, which means if you try and go back in the browser, or refresh the page you get that annoying 'are you sure you want to submit this data again' pop-up.

Models are set up in a very similar way to how I've been taught to safely set up object with functions to call and set properties rather than setting the variables directly (this avoids accidental assignment).

Zend Tutorial

The tutorial was pretty good at helping me understand the basics of MVC.
That's about all the good I have to say about it.

The tutorial wasn't very well written and basically was just a load of code to cut and paste into your application. The 'Create a Model page' was particularly confusing by getting users to create a script to populate the database with sample data when it could have halved the size of the tutorial by just giving the SQL to create the records.
I know nothing extra about the Front Controller pattern as all the code dealing with that seems to be hidden in the Zend source code. I realise the tutorial makes no promises about this, but I was disappointed nonetheless.

Sunday, 17 June 2012

Part way through the Zend tutorial

The Zend quickstart tutorial is really helping me get to grip with the MVC and front controller way of doing things. Although I'm not yet connived that it is the best way of doing thing, I am beginning to understand it, how it works and the reasons that people think it works well.

I thought I would quickly share a few things at the halfway stage.

Development Environment

Zend makes a lot of fuss about file structure and while at the beginning of the project my plan was to keep things as basic as possible and only use a text editor to edit my files, I caved in. I installed NetBeans in order to see the file structure of the quickstart project. This was actually quite good for understanding where all the files lived.
In order to install NetBeans, you must first install the JavaSDK which you can do by typing sudo apt-get install openjdk-7-jdk in a terminal window.
You can then download NetBeans from
Once you have done that, open NetBeans and choose New Project. Then just navigate to the quickstart folder.

MySQL vs SQLite

The ZEND tutorial on creating models uses SQLite as the database of choice. Whereas this blog only talks about MySQL. The tutorial starts talking about initializing a Db resource. Read this part but don't follow the instructions to do with SQLite or creating scripts (you can if you want as you can revert it afterwards). Instead follow the simple MySQL instructions in this comment. You can then pick the tutorial up again where it starts talking about a Table Data Gateway.

Saturday, 16 June 2012

Slightly off topic - IE7 Tax

The beginning of the end

For Internet Explorer 7

Australian retailer recently had their website revamped. But instead of using all the latest technologies to make the website better, they found that the web development team were spending a lot of time and money making the website IE7 compatible.
This lead to them imposing a tax of 6.8% for people making purchases using the antique browser.

This is in-line with my views of out-of-date technologies as I outlined in my first blog post, where I stated that the framework I plan to build will not try hard at all to be backwards compatible with old technologies. I am pondering if I should include a pop-up for users of old browser suggesting they download a newer one.

Something I find amusing is that the pop-up on the site warning of the tax doesn't suggest IE9. Just Chrome, Firefox, Safari and Opera.

You can find out the percentage of people using browser at the w3schools site. At the time of posting, only 2.1% of people use IE7. There is also a group of people campaining against the use of IE6 over at . While we're on the subject of IE6, it may be worth noting that Google stopped actively supporting IE6 in 2010.

Learning the MVC principles with Zend

Getting to grips with MVC using Zend

As I mentioned in a previous post, I could neither get to grips with or understand the positive aspects of programming using the MVC principles.

It was recommended to me that I follow the Zend Framework quickstart guide. Apparently it gives a good basic understanding of the MVC principles and will take around a day to work your way through it.

I started setting up the Zend Framework on my computer a few weeks ago, but got stuck and frustrated several time and could not force myself to go back and try again. It is not the simplest thing to set up if you're not used to configuring system files such as PHP's .ini file. But I have finally got there!

The quickstart guide navigation is not all that friendly I found and so I will put some links at the bottom of this post.

There were several places that I got stuck while setting up the framework. The last and most frustrating is when I actually visited my local version of the quickstart site to be greeted with the error 'Warning require_once(Zend/Application.php)[function.require-once]: failed to open stream: No such file or directory in /home/michael/Projects/quickstart/public/index.php on line 18'. I'm still convinced that I must not have followed the setup guide correctly, I followed it through twice after to make sure I had done everything and set up any symbolic links I needed to.Google didn't seem to help. I finally gave up and started messing around the the set_include_path call on the index.php and added under the realpath bit '/home/michael/Zend/ZendFramework-1.11.11/library' it finally worked! So if you get that problem, just put that bodge in.

I am now greeted with the following image. Boring, but satisfying.
I imagine my next post will be when I have completed the guide. (Probably in a few months)

Zend Quickstart links:

Download Zend and then follow install.txt

Saturday, 26 May 2012

Slightly off topic - EU Cookie Law

EU Cookie
Today is the deadline for compliance with the EU Cookie Law. The Law came into effect a year ago but no websites were ready for it and were given until today to comply.
In my opinion, this is a ridiculous law that was either rushed, or dreamed up by people with little understanding of cookies and internet security.

Cookies are good

Cookies can help remember on-line shopping baskets when you come back to a website, they can allow you to sign into multiple website via one login (such as clicking the Facebook 'Like' button on a non-Facebook page) and result in targeted adverts (meaning that I don't need to be shown as many adverts).
If I come across any website asking if I will accept cookies, I will first off be annoyed that my internet browsing experience has been interrupted and then click accept.

Most modern browsers have an option to block cookies anyway, and if people aren't using modern enough browsers, they have larger security issues to worry about than Cookies.

I can't think of a single good reason for this law.

No EU Cookie Law

Related links:

Article in favour of the cookie law
I couldn't find any articles in favour of it.

Comment below with your opinions on the EU Cookie Law

Monday, 21 May 2012

Roadblock - MVC

MVC seems good in theory, but what about in practice?

Well... I have become stuck already. I have been investigating the principles of MVC and tried to create a simple 2 page website, but I have become stuck at the point of splitting up the separate components.
One of the things that has made me scratch my head most is that many people insist on a single entry point when building an MVC framework. I am currently awaiting a response to my comment on stackoverflow to see why this is a good idea. To me it seems very insensible for several reasons (I have not looked into these reasons too much so I could be wrong):
  1. Passing information through the URL doesn't seem very human friendly.
  2. It depends on how the MVC framework works as to how the parameters are used to fetch a page which could make debugging harder for an outside developer.
  3. Can Google Analytics deal with a single entry point?
It feels like this approach may be more suited for some sort of Javascript type single page that works more like a program (or web app) than web pages. Does anyone have any decent examples of websites with single entry points?

I get the feeling that I am taking the phrase "single entry point" too literally. Perhaps the point of a single entry point is to set everything up in a unified way (database connections, security, page headers and footers etc...)

Going back to MVC rather than single entry points, I can't find any explanation as to whether each page needs all the components.

For example, many websites revolve around adding, editing or removing data using forms. To process forms using PHP requires POSTing the data to a PHP page.
With the current framework I use, the forms mainly POST to the page they're on and check the $_POST superglobal to see if the form has been submitted, if it has, the page processes the form, if not, it displays the form. To me, this approach seems silly, to mix processing and display. And also causes problems when refreshing.
With the framework I used at my old company, all form processing was split over three pages. The form page, a processing page, and a success page. This seems a lot more logical way to process forms using PHP, but in this case, the process page would not need a display component as it mearly processes data. Which is why I'd like to know if M,V and C are required for all pages.

I have made a tiny example 3 page website. Which you can download the zip for.
Each page is based on a viewController class which has a view passed to it. The view extends the model. There are base classes which should be generic and then classes that extend those specifically for the 'testytest' example site. I'd like to challenge someone to recreate this 3 page site in their neater, own MVC way and send it to me.
It seems a bit of overkill to have so many files. Another question I have is, does the M,V and C have to be explicitly separate? or can they all exist separately in the same class?

I find 'helper functions' useful. I think these might be classed more as library functions than part of a Framework. Should these be included in the Framework? or should they be in a separate 'library' folder?

Sorry if this post is a bit of a mess. I was just trying to get all my ideas down. I'll try and tidy it up later.

Please comment with your ideas, input, suggestions and articles regarding any of the concepts mentioned in this post.

Saturday, 19 May 2012

First local LAMP site

It's all coming together...

In my post about installing PHP, I created a small script to see if it was a birthday or not. I'm now going to turn this into an actual local site using all the constituent parts of LAMP and some CSS. Using MySQL may be a little overkill, but I think it would be good to practice first on a nice simple site.

I already have the site set up in my hosts folder located at /etc/hosts.
My virtual hosts file is also already set up but seems a bit bloated. At the moment I will leave it as it is. I think a future post about virtual hosts may be a good idea.

Create a database in mysql
CREATE DATABASE isitmikesbirthday;
USE isitmikesbirthday;
I now need to set up a user for my script to select from the database as and set up any database tables I want.
GRANT SELECT ON isitmikesbirthday.* TO 'iimb'@'localhost' IDENTIFIED BY 'password';
Then create a table with for my information
CREATE TABLE persons(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(10), last_name VARCHAR(10), date_of_birth DATE);
I then need to put some data into the table
INSERT INTO persons (first_name,last_name,date_of_birth) VALUES ('Michael','Gwynne','xxxx-09-27');
That should be the MySQL part over. Now to the PHP script. It should be pretty self explanatory. This script should also be foolproof and have all the error checking needed in it.

Hmm, it seems I can't paste PHP code into Blogger. I'll have to find a work around and come back to this. Unless anyone knows how to.... please feel free to comment below.
In the mean time, you can download my code in order to have a look at it.
Simple site

There are several things I realise are slightly bad practice in my code.
  1. Some of these things like the class and CSS should be spilt into separate files.
  2. The member variables of Date should not be public and should be instead called by helper functions to avoid accidental assignment.
With my first two goals in mind:
  1. Google Friendliness (Speed, W3C validation etc..)
  2. Neat, Readable, Self-documenting code
Please have a look at the code and see if you can find any ways to improve performance, readability and security. Comment below, add reasoning if neccessary.