Web Design & Development

Archived posts from this Category

How smart is Smarty?

Posted by admin on 18 Feb 2009 | Tagged as: PHP, Web Design & Development

I started using the smarty template engine today for one of the applications that I develop at work. The application previously used a home-made templating system that was much more primitive in comparison. It was basically a string replacement engine.

I had started reading the documentation on the Smarty website a few days ago, and I must say, I am impressed with what this so-called “template engine” can do.

I quote template engine because on the offset, that’s what Smarty appears to be. But upon further investigation it becomes apparent that Smarty is much more than this.

During the day or so that I have been using Smarty, i have come to appreciate it’s built-in function base, that takes care of things such as loops and conditionals with ease. Meaning that it really can be used as a full presentation layer instead of a string replacement/templating system.

This ability to have conditionals and language constructs purely in the presentation layer means that one can use PHP to obtain and sort the required data, into arrays if necessary and then pass on the raw data to the template which can then decide what to do with it, or how to display it. This is the limitation of more simple string replacement templating systems.

Although I am still new to the Smarty way of doing things, the more i discover about Smarty, such as it’s built-in language file support, and auto-generation of HTML select/option tags given an associative array the more I like it.

Only time will tell if it can cut the mustard though, once it’s been implemented on the whole application and tested. But from what I’ve read, it’s up to the job.

SVN on Linux and Windows

Posted by admin on 17 Feb 2009 | Tagged as: Uncategorized, Web Design & Development

Working within a development team on applications usually requires some sort of version control. Version control software such as the newer Subversion (SVN), and older Concurrent Versions System (CVS) store a version of the developmental code internally in a “repository” and allow as many people as required to “check out” or obtain a copy for themselves. These applications have many uses, but the main uses are the distribution of code, and the subsequent saving of updated code once a developer has finished working on it. All version control software have this functionality. Plus the ability to lock files that are being worked on and  prevent or merge multiple modifications to the same code. In short, they are an indispensable tool for multi-developer applications.

Developers who use Microsoft Windows and need access to an SVN ro CVS repository have the option of using an extremely good, open source GUI client called TortoiseSVN (or TortoiseCVS as required).

TortoiseSVN won the SourceForge.net 2007 Community Choice Award for Best Tool or Utility for Developers. Using this GUI client means that the user can perform many actions that would require a more in depth knowledge from the command line.

Unix and Linux users do not have the luxury of the TortoiseSVN GUI client to perform actions on a CVS/SVN repository. There are alternatives, such as RapidCVN which is cross platform but I’ve never tried it so can’t comment. Maybe I will at some point.

Whichever Operating system that you use, it’s always useful to be able to get by without a GUI client from the command line. So here’s just a few useful commands…

SVN Checkout

svn co url [destination_directory]

or

svn checkout url [destination_directory]

Ignore a directory

svn propset svn:ignore directory ‘dir_name’

Show status of files and dirs

svn status

Add a file

svn add file_name

Commit

svn commit [file_name] [-m "some comment"]

If you require more, there is a useful resource of commands here.

A really simple introduction to templating using PHP

Posted by admin on 01 Nov 2008 | Tagged as: PHP, Web Design & Development

When developers talk about application development they often spout things like

“When developing an application it is beneficial to separate business logic from the presentation logic”

Which all sounds very technical and intellectual, but what are they going on about when they say things like this?

Imagine a simple website. Three pages liked together by hypertext links. Each of the pages contain text and images hard coded as HTML and the files have a .html extension. There’s no processing behind the scenes, no PHP/ASP or Java, the pages content never changes. These are called static pages. It would be fair to say that this website is almost completely made up of presentation logic. Logic, or code concerned with display and not processing any information.

Now, imagine a PHP scrpt that a form on this website posts it’s information to when someone clicks the submit button. Let’s call it ‘process_form.php’, and lets say this form takes the information posted to it, checks the information is usable, and then redirects you to another page depending on what you entered in the form. This processing of information would be an example of business logic.


Often In web applications, business logic and presentation logic, along with CRUD (database logic)  are often fused into single scripts. Such as having a single PHP script that does some processing and outputs the result in HTML format. Though often useful, this can become problematic and cumbersome if you wanted to change the way your web page looked without changing the way it does any processing.

Along comes templating…

Templates allow you to seperate your static content from your processing. This way, you could easily change your static content without worrying about the processing code getting in the way and vice versa.

A simple HTML file could look like this:

<html>
<head>
<title>Title Text</title>
</head>
<body>
This is the content
</body>
</html>

If we wanted to output PHP in this file we could do something like this:

<html>
<head>
<title>Title Text</title>
</head>
<body>
<?php echo ‘This is the content’ ?>
</body>
</html>

This would be an example of single-tier, or fused logic. Which makes it difficult to just change our HTML because the HTML and PHP are intertwined in a single layer. Say we created a template file of our original HTML file that looked like this and gave it the extension .tpl

<html>
<head>
<title>{TITLE}</title>
</head>
<body>
{CONTENT}
</body>
</html>

In this example we have replaced the content withcontent placeholders that we can reference later on.

Now, we can produce a simple PHP function that will replace the placeholders with our content after our PHP business logic layer has finished with it. The function may look something like this:

function render($array,$template){

$template = file_get_contents($template);

foreach ($array as $key=>$value){
$template = str_replace(’{’.strtoupper($key).’}',$value,$template);
}

echo $template;
}

This way, from our PHP business logic layer, we can easily produce our presentation layer with any data we like without having to alter the template in any way. An example of calling our template from the business logic layer would be something like this:

render(array(’title’=>’The Page Title’,'content’=>’This is the page content’),’template.tpl’);

Passed the MySQL Dev II Exam - Now a CMDEV

Posted by admin on 24 Sep 2008 | Tagged as: Web Design & Development

I took the second MySQL Certification exam on Friday and I am now proud to call myself a “Certified MySQL 5.0 Developer”. It always feels good to add another qualification to the list, and reinforces the fact that I am actually a LAMP developer and not just a PHP developer.

For those of you who don’t know, MySQL (or Sun or whatever) offer two different certification routes, Developer (CMDEV) and Database Administrator (CMDBA).

The Developer certification, supposedly designed for developers who use MySQL for back-end data storage and processing such as integration with web applications, and the DBA certification, more for those

sysadmins who optimize ,tune and maintain MySQL servers.

Some people may not like this about me, but when it comes to application development I’m a bit of a perfectionist. I put a lot of effort into what I do and I try really hard to get things exactly right. I only bring this up because in some respects it explains my disappointment with the exam.

There were so many visible errors that I was actually angry whilst taking the exam. The numerous errors consisted in simple misspellings of SQL keywords, to missing spaces between parts of SQL queries and repeated words. One question gave a multiple choice of four SQL queries, asking you to select the correct one. In actuality they were all wrong! If I had cut and paste each of those queries as they stood into the mysql client program, none of them would have succeeded.For a company that has such a great product I am saddened by the low spelling quality of the exam questions.

The questions themselves, on the whole were fair. If you could settle with selecting the “best” or “closest” answer instead of the “correct” one. The range of topics tested fairly accurately matches the breakdown stated in the MySQL Certification Study Guide (ISBN 0-672-32812-7), which was almost single handedly my source for study material. The questions given on the supplied CD are exceptionally useful.

There are several things that bother me about this certification at the moment though. Exam spelling mistakes apart, there are only 525 people worldwide who hold the MySQL 5.0 Developer Certification, with only 30 certificate holders here in the UK (USA holding the most at 204). I am the only person in  the whole North-west of England who holds the certification. Now this could be for several reasons, either the CMDEV is:

  1. Not very good and not worth having
  2. Not recognised by employers
  3. Its really hard to pass
  4. People do not know about it.

I think It’s safe to rule out 1 & 3. I think the certification testing was adequate and the difficulty level was intermediate. Fair for a cert of this nature.

This leaves 2 & 4. Which in my eyes are related. In my opinion, a certification for developers using the most widely used and successful Open Source RDBMS available should be more widely recognised and utilised by employers and developers.

I think that MySQL /Sun need to increase people’s awareness of their certification program as this could be a very handy little cert to have.

Useful Content Ratings System for the Web

Posted by admin on 31 Aug 2008 | Tagged as: Web Advertising and E-business, Web Design & Development

When producing a website a content rating identifies the type of content, such as language and pictorial content of the website through a method of labelling. This can be used to stop unsuitable material being displayed to the wrong people, such as sexually explicit or obscene material to schoolchildren.

The ICRA (Internet Content Rating Association), part of the Family Online Safety Institute is an independent body that produces a questionnaire for webmasters to fill out regarding the content on their websites. The answers to these questions generate a small file which contains a series of labels that can associated with a particular domain that identifies the type of content contained therein. Users can then use filtering software (sometimes integrated into their browsers as a plug-in but not always) to allow or deny access to a domain and its content depending on these labels.

The ICRA’s content rating system is totally optional and is a self-rating system where the websites administrators generate the rating themselves by answering the questionnaire, however the resulting ratings are still checked by the ICRA.
There are other methods that can be utilised by third parties to produce a content rating for your site, but these are done by others and not in the hands of the web publisher.

Next Page »