How Many Tiers for a Clean View Layer?

An interesting possibility cropped up for my MVC a few weeks ago. I've been working with microformats on and off the last few months (you can read about one of my first adventures with them when I created a microformatted resume). I started to wonder where else my site could use this new feature. An easy place to add microformat tags are links - you can add a 'rel' attribute that describes the relationship of the link to your site. Also, if I added a layer of abstraction to my links site wide, then I could easy add behavior rules (target="_blank" and whatnot) that would affect an individual link across all of my pages and sites.

This idea would involve creating a table of all my links, internal and external, that could be mapped to meta information about the links. There would be a helper class on my site that would pull a link based on an alias, give it attributes based off of the meta data (including microformatting), and spit out a final link. No where on ...

read more »

Microformatting the Resume

When a computer script crawls across the web looking for information (like Google's search robot) they need to do a lot of thinking to figure out what information is located on a web page. After all, web pages are written by humans for humans, with the data and information contained in our complex, contextual language. Web developers can help a script understand their site with robots.txt, xml feeds, and designated syntax (like using h1 tags for headers), and more recently, microformats.

The best way a script can understand text is by tagging it. This is how some xml formats work - you wrap the title with a <title> tag, set relative priority with a <priority> tag, etc. However, xhtml and older html formats only let you wrap normal web pages with standard tags, like p (paragraph), h1 - h6 (headers), etc. Microformats uses attributes of tags (like class names) to help computers understand what the content of a page is instead of the actual tags.

I recently dove into microformats with my resume, located on my ...

read more »

Abstracting the Resume

Recoding all of my subdomains to follow a model-view-controller framework has been a really interesting process. I've had the opportunity to experiment with different design patterns and techniques, especially in the realm of data handling and content delivery. Abstracting out my resume is a great example of how I'm handling my data in a way that provides necessary functionality at the moment while staying flexible enough for future rewrites.

Until recently my resume was written inline with html tags, merely included into different web pages as needed. This was a bad solution - every time I wanted to change a piece of it I had to wade through html tags. I couldn't place any dynamic content in my resume or reuse it in non-html formats. A cleaner solution was needed.

My first step was to divide up my resume into pieces. I have five main categories: objective, job history, skills, achievements, and education. The objective is a single line of text while the other four categories are lists. Some of these lists are lines of text while ...

read more »

My Lifestream

As a web developer interested in creating a web presence I'm constantly looking for new projects to add to and inhance my websites. Some of these (like this blog) require a fair degree of committment to create new content, while others (like my about page) is a simple static page. I've always kept my eye on my social networks as a potential source of content for a new site, and the recent launch of my lifestream (lifestream site) fits my needs very nicely.

There's numerous examples of web developers using this technique on their sites. An obvious one is a display of a personal twitter feed on a page, usually on the home page or blog, as both a constant source of content and a way to collect possible followers. I've seen some more advanced uses too, including github activity.

I decided to do something a bit more ambitious with my lifestream. The concept of a 'lifestream' is a compilation of time-ordered online activity ( ...

read more »

Thoughts on Data Abstraction

Something that I've been working on a lot with both my work and personal web programming is data abstraction. The opportunity to work with several different handmade php frameworks has given me different ideas on what an effective data abstraction system should have. Without formal education, though, this post will be only based on my hands-on experience with the functionality I find myself using without true design patterns.

Data abstraction is a fancy word for treating the data as a separate entity from your web application logic. Web sites usually store their data in databases, using customized queries to pull information for their code to output and manipulate information. It doesn't matter what type of database or language you're working with; data abstraction can be employed whenever there is interaction with data (this post will be approaching this from a rough PHP - MySQL angle). Complex sites often have numerous queries scattered throughout the web site, and one needs to have intimate knowledge of the database structure during the ...

read more »

The Problem with Assuming

In the days of old (PHP 4) web programmers sometimes resorted to small shortcuts in their code. One of these was register_globals, which extracts the global arrays ($_REQUEST, $_POST, etc) into individual variables, allowing a programmer to write $name instead of $_POST['name']. This is an obvious security flaw - users can easily pass in custom parameters to overwrite variables in the code and cause unforeseen problems. In the below example, if register_globals was turned on in the PHP configuration, a tricky user can pass in a 'access' parameter and do some horrible things.

if($level == 'admin')
{
  $user = 'admin';
  $access = 'everything';
  $restrictions = 'none';
}

if($access == 'everything')
{
  // do some horrible things here
}

This is a good example of a bad programming practice - assuming that things will work the way you expect them to. That is, you assume that a level of 'admin' is the only way the 'access' variable could be set to 'everything'. The security-orientated approach would be to ...

read more »

Why (some) Client-Developer Relationships Suck

Some web development projects don't turn out. The blame falls on both the web developer's and client's shoulders, though most developers will pine about the 'Worst Client Experience Ever'. It doesn't matter if the project is related to a full-time position or a one-time contract... things don't always work out. A combination of misunderstanding and miscommunication can ruin the best of working relationships, pushing back deadlines and frustrating both parties. There are two main causes for why this happens.

Web Development is New

The entire field is brand new, and whether a developer has been working for the past few months or the last decade, it's important to treat it as such. While the majority of people understand how to use the internet, there's a great deal of mystery about the experience. This goes beyond users not understanding the difference between Flash and Javascript and straight to developers themselves. Payment, expectations, and techniques differ greatly between individuals and projects. Also, it's far too easy for a ...

read more »

Beginner Web Developer Mistakes

With my introduction into web development coming from a static html/css direction, I've had to overcome several bad coding habits over the years. Most of these started with poor assumptions about the way websites worked. It took a crash course in php programming and a few hard bumps before realizing how wrong my first websites really were. Here are a few of those assumptions and how I built on them to increase my programming skills.

Each URL relates to a unique file on a web server

If you're only used to working with static html files than this assumption is largely true. Every different URL that a user visits on a web page is in reference to a different file on the server. Without any type of scripting, the file is merely a chunck of html and can only be changed by a webmaster physically manipulating the document. My first dynamic website used php include commands to pull a fixed header and footer for all of my pages, allowing me to make global site changes from a single file. When I finally started to learn more about php variables ...

read more »

Revisiting the Database Class

Several months ago I wrote a blog post describing how to create a database class that would wrap the native php mysqli connection. You can read that post here. Since that post was written I've learned a lot about proper php classes and realized that I made several mistakes in that blog post that I'd like to revisit.

Singleton

The database class that I wrote constructs a new read/write connection whenever it is instantiated. However, there is nothing unique about this connection - it remains the same no matter how many different instances you have of this class. There should be only one instance of this class in this case. If you have several different connections (say, a different user for each of your databases or schemas) then you'd have to look at passing connection information into the class through a factory class, but this case requires a singleton.

A singleton class is fairly simple to make. By making the __construct method private and ...

read more »

Intro to SQL Part D

For the last post in this short series on SQL I wanted to explain some more in-depth usage. A technique that I wish I would have started using in my early websites is a centralized script to handle all of my database calls. PHP does have some great functions built in to connect, read, and write using SQL statements (check out mysqli), but it's easy to start copying the same eight to ten lines of code every time you want a piece of data from your tables. A better approach is to handle the queries with a centralized class.

Before anything can be read or written to a table with a SQL statement, you need to create a connection. Your website will be signing as a user with specific privileges. A good technique is to make two users, one that can read and one that can read and write. By using the former user as much as possible and taking extra care with the latter one, you will minimize the possibility of hackers uploading malicious information or dropping whole tables.

Once a connection is made you can start having fun with the database ...

read more »