Friday 22 June 2012

Zend/Zend tutorial review

Zend

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 http://netbeans.org/
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 Kogan.com 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 ie6countdown.com . 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.
isitmikesbirthday?
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.

MySQL

Once again using the useful article in the community section of the Ubuntu website, I will install MySQL. MySQL is database management system based upon SQL. As with all things, if you'd like to know more, check the MySQL Wikipedia page.

The single line command you need is
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
These are 3 seperate installs and as far as I can guess (and I am guessing):
mysql-server is the main part of the MySQL program
php5-mysql is a PHP module for MySQL
libapache2-mod-auth-mysql is shown from a quick Google to be "A module for the Apache 2 web server which enables HTTP authentication against information stored in a MySQL database".

The article suggests changing the memory limit, but I am going to leave it as 128 as I can always increase it later. I imagine it must be more efficient to leave it at the lowest level possible other wise surely it would just be set around the systems memory limit.

I am not installing any database administration software like phpMyAdmin yet as using the command line gives you more control and you can understand the behind the scenes workings. This will be a massive pain to begin with but should get easier as my knowledge grows.

One thing I didn't see in the article is that you need to restart Apache.

Friday 18 May 2012

PHP

Installing PHP5

This useful article again tells you pretty much all you need to know.
2 (or 4) simple things to do and PHP is set up on your machine.

That wouldn't make much of a blog post. So I'm going to make a simple PHP site and set up my folders and settings before I move on to installing MySQL.

Settings and Folder structure

I decided that seeing as I would be creating projects, I would have a "Projects" folder in my home folder. Just use the command line or the GUI to do this.
If you were following the article mentioned above, you need to deactivate the site "mytest" by entering the following on the command line.
sudo a2dissite mytest
Now copy one of the virtual host files I named the copy "isitmikesbirthday".
I opened up this file and changed the DocumentRoot to /home/michael/Projects/isitmikesbirthday and changed the Directory to /home/michael/Projects/isitmikesbirthday/
After that I put an entry in the hosts file. In /etc/hosts I added the following line
127.0.0.1 isitmikesbirthday.local
Then I needed to enable the site with
sudo a2ensite isitmikesbirthday
And restart apache
sudo service apache2 reload

The first PHP script

All that's left is to create and index.php file in the folder Projects/isitmikesbirthday/
And it's in that file that the magic happens. I put...

<?php
if(27 == gmdate("j") && 9 == gmdate("n"))
     echo "Yes";
else
     echo "No";
?>

Thursday 17 May 2012

Apache

Apache is HTTP server software. Apart from that, I'm not 100% sure what it does, I'm sure once I delve further into it I'll understand. In the mean time, read the Wikipedia article.

There is already quite a detailed article on installing Apache on Ubuntu on one of the Ubuntu community pages. This is the article I worked through and it seems to work fine.

It looks like it is possible to install almost everything you need for your L.A.M.P fun in two simple lines.

sudo apt-get install tasksel

then

sudo tasksel install lamp-server

But that's cheating!!
Anyway, I started this project to learn every step of the process, not to cheat.

Installing Apache2

I followed the Installing Apache 2 part of the article.
Incase you're brand new to using the command line I'll explain a few little things quickly.

sudo

- allows you to run programs with the security privileges of another user

nano

- is a text editing program

cp

- means copy

All reasonably easy once you get used to using the command line.

Editing Apache Configuration

A little further into the article is a section titled Edit Apache Configuration which lead me to another article about securing your Apache configuration. It seems it is safer to run Apache in it's own account. One day I'm sure I will find out why.

Securing Apache

Towards the bottom of the article is the section on Securing Apache which basically explains how to make sure that no one can access your development websites from another machine.

All in all that was surprisingly easy, even though I was blindly following instructions.

A little tip: If you try running a program but forgot to use sudo at the start, you can re-run it by typing sudo and double exclamation marks (sudo !!)

Linux (Ubuntu 12.04 (Precise Pangolin))

I am installing Linux as my Operating System for several reasons. For starters, Linux is what the 'L' stands for in L.A.M.P. The other two reasons are that I use it at work and would like to get more familiar with it and also that most servers run Linux.
Ubuntu is a free, open source 'flavour' of Linux which has a graphical user interface as well as text-based input. Version 12 is an LTS which stands for Long Term Support, meaning that it should be supported for at least 5 years.

In order to do a fresh install of Ubuntu on an OSless PC you first of all need to make a USB boot disk:
  1. Download the Ubuntu .iso from the download section of the Ubuntu website.
  2. Download Universal USB Installer.
  3. Put a USB in a USB slot and open Universal USB Installer.
  4. Choose the Linux version you are going to installer and the location of your Ubuntu .iso file
  5. Follow the rest of the instructions to create the USB boot disk.
Then all needs to be done is install Ubuntu on the new computer:
  1. Put the USB stick in the new computer
  2. Turn the computer on
  3. Select 'Install Ubuntu' from the options
  4. Follow all the instructions (they are pretty straight forward)
  5. Fill in the details for your machine. My machine is named Thomas (after the friendly engine)
The computer then does it's thing for around 20 mins and then needs a restart. You may find that the update manager also wants to install some updates straight away, this is fine. You should do another restart afterwards.

What impressed me:

  • No need to get drivers for the graphics card or wireless card.
  • It seemed to be pulling in live Tweets on the installation screen (how can something pull in live tweets from the internet without the OS even being completely installed???)

Problems I had:

Use the slider to change the overscan compensation
  • At first the display was too big. This is an overscan setting of the graphics card. In the console* I typed

    nvidia-settings

    and up popped the setting panel where I changed the overscan compensation settings using the slider.
  • The computer wouldn't connect to my wireless router.I assume it was because the Ethernet cable was plugged in, or because the cable was plugged into the same router. I unplugged the cable and next time the computer started up, it was fine.
  • I restarted the computer and it booted onto the command line instead of the GUI. Turned it off-and-on-again and it seemed to be fixed!
*In order to get the console up, just hit Ctrl+Alt+t

Wednesday 16 May 2012

The Hardware

Unboxing
Box full of goodies
The engine I endeavour to create should be efficient, therefore I have bought pretty much the cheapest machine I could find.
This lead me to Novatech where I bought the most basic Isys V2 which has an Intel Celeron G530 processor which is 2.4GHz, dual core and 64bit. The memory with the computer is 2 x 2GB 1333MHz DDR3. Simplez.
Since I didn't want to use a monitor, I bought a graphics card in order to connect my computer to my HD TV. The graphics card in person is a Novatech GeForce 210. The last little add on was a Novatech 300Mbps 802.11n Wireless-N PCI Adapter. This all came to a grand total of just under £300, which isn't bad. It was delivered free two days later AND to top things off, when I opened the box, they had thrown in a keyboard and mouse.

Fitting the extra components was easy. Unscrew a few screws to take the side panel off. Rip out two of those back bracket things (feel free to leave the correct terminology as a comment below). Push the cards in and screw them to the case.
Graphics card installed
Graphics card fitted to the motherboard

Tuesday 15 May 2012

The beginning

The first post:


The point of this blog is for me to chronicle my attempts set up some websites from scratch. As part of this I hope to build my own PHP based MVC framework (engine).

About me:

I left uni in 2009 with a degree in Robotics. I returned to my home town and found it extremely hard to find a job. Eventually a web agency called Switchplane hired me even though I had never done any PHP. The two bosses, Tom & Joel, trained me up in PHP and MySQL. Tom and Joel had created their own framework which at the time I was impressed with but wouldn't truly come to realise it's awesomeness until I left and worked with other frameworks.

When I left the company, I left the comfort of framework I learnt to code in and realise that I didn't actually know the basics of PHP, how some HTML actually works and Apache, among other things.

In my new job I deal with a new framework and the other parts of L.A.M.P. development Linux and Apache. This prompted me to learn every stage of creating a website so that I can perform better in my job, in the future and hopefully help some others learn with me (or correct me) along the way.

My aims:


  • A PHP MVC framework
  • Object oriented
  • For the 95% (eg. won't try to hard to support IE6 etc...)
  • Up-to-date (HTML5 + CSS3)

Priorities:


  1. Google Friendlyness (Speed, W3C validation,Blind user accessibility,semantic web)
  2. Neat code
  3. End user usability
  4. Support for older hardware,software


The idea of this framework is that you never need to edit the framework, you will extend it or copy parts to a separate project.

Upcoming posts should be about the hardware and Linux.