Why You Should Build Your Own Darn Framework (Usually)

I've always been a big fan of writing my own website frameworks. It's how I learned to code, writing and re-writing a specialized PHP framework in an iterative, agile-like development process. There have been times when I've worked within standard systems (Zend, Code Ignitor, Wordpress, etc) but I try to avoid them on personal projects. PHP has a lot of flexibility in terms of allowing a developer set their own standards and I have a very unique style and approach to custom projects that I bring to my code. Also, I have some issues with using a pre-built framework.

Too Much Functionality

Some frameworks are very abstracted out with functionality for multiple data source drivers and DOM helpers (cough cough Zend). While it is impressive how much thought went into these large, comprehensive frameworks, there is often far too much logic there for a standard web project. As an example, one of the previous systems I worked with (heavy-traffic, front-facing site) was based off of the Zend Framework. Each page load included over 300 scripts ...

read more »

Abstract Form Handling

I've already gone over some basic form handling and form best practices with my last few posts, but building with an object-orientated MVC starts to throw forms into a different light. It's very easy to abstract out forms with their repetitive logic patterns, something that I've recently done on one of my side projects. While I don't want to explain the code line-by-line, this post will go over some of the basic thought processes and steps I took to make my abstracted form handler.

Form Wrapper

The first logic I worked out was the definition of a form. To create each new form, I create a new class that is abstracting off a base pattern. Each form class defines form elements within a standard 'get' method. This way I can call on individual form elements easily or call the entire class to pull the whole form. Example...

read more »

Best Practices with Forms

The last post about PHP form handling (forms with php) focused on the basics - the HTML syntax and simple PHP necessary for an operating form. There were several pieces that I glossed over in the explanation for the setup of that form that I want to go over in more detail now. You can create a form using many different techniques... but some practices are better than others.

Use Standard Elements

By using Javascript or tweaking HTML elements you can create a working form without the standard form elements (input, textarea, checkbox, etc). Normal HTML form elements often have annoying default styles added to them by different browsers that may conflict with your design. While it may seem like a good idea to hack their behavior, there are two reasons why you shouldn't.

First, if you don't provide graceful degradation, there's a good chance that your tweaks may make your form unusable by more basic browsers and systems (like screen readers!). Second, users are used to certain ...

read more »

Basic Forms with PHP

HTML forms are a great way to collect information directly from your users. There are plenty of input options available, even for the most basic, non-javascript enhanced forms. This post will go over the steps for creating, validating, and handling an elementary contact form with PHP and HTML.

We'll have to make a few basic assumptions before beginning. First, we'll assume that the page the form is displayed on can be executed with PHP. This could mean that either the page has a 'php' extension or the web server is configured to run this file as PHP, regardless of the file extension. Second, we'll assume that there is no conversion tracking (that is, analytics tracking the number of page visits vs the number of form submissions). This will make our submit logic a bit simpler. Finally, we will not be doing any javascript or ajax trickery. All the fields and submit request are handled as browser defaults.

Our initial step involves setting up a basic html form. We'll be submitting via the 'post' method, which passes the form parameters ...

read more »

Connecting to a MySQL Database with PHP

Working directly with the database is something I rarely do any more with the applications I work with. Instead of creating a raw connection and pulling data directly, I usually utilize some sort of customized data layer. (If you don't know what a data layer is, imagine creating a PHP application with no queries. You still have data being pulled, usually from MySQL table, but the data storage and structure is kept independent of your application. When done correctly, this can help immensely with code cleanliness and development.) However, setting up a connection and pulling information is still an important skill set, so here is a post about the basics. If you're looking for information that is more basic than a PHP-MySQL connection, you can read my series on the basics of the SQL language.

There are several ways to connect to a table, but I'd highly recommend using the MySQL Improved Extension, or mysqli, as a simple but powerful way to connect to your MySQL ...

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 »

Salmon Trout Point

Just north of Big Bay the shoreline makes a final reach north before curving westwards into Huron Mountain Club property. The land here is strangely flat, with an elevation of 120 feet above Lake Superior. Instead of rolling gently down to the water, the forest abruptly stops at cliffs that plunge straight down to the shallow water. Only a few cabins and roads dot the area, making it a large, flat, and empty area jutting into Lake Superior. I probably never would have visited it if it hadn't have been for a fellow hiker who pointed me towards an amazing hiking adventure.

Looking south from Black Rock Point

Looking south from Black Rock Point

My first visit to this area was with Katie and Logan. We had been out all day and were more than a little tired by the time we reached Big Bay. Parking where Sullivan Creek begins to turn left, we headed east to the water at Black Rock Point. A gated two-track took us right to a small camping spot near the small point. This point is really just a small dimple sticking out from the otherwise straight shoreline with ...

read more »

What's With the Big Pause?

When I first decided to create an online blog I wanted to avoid a common pitfall of many other blogs: lack updates. While there were a few empty months in 2009, it feels like a did a good job with regular posts every week or so... Until the New Year rolled around. This is the first blog post in over six months.

Starting in mid-November a few things changed that really impacted my regular blogging. The first, and most obvious one, was winter. While I do enjoy winter adventuring, driving to the Upper Peninsula through the snow to come up with fresh content for the hiking side of my blog was something I decided to avoid. That, coupled with decrease daylight and other seasonal blues, dampened my motivation to write new hiking blogs.

Another problem that I ran into was a decrease in time. Not only did I start working later hours in November at my full-time job, but I started a large contract project that ate up any free time I normally reserved for my personal site development. My site was half rewritten at this time - I was starting to ...

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 »

Basic Tag Cloud

This post assumes basic understanding of PHP, HTML, and CSS.

Creating my blog by hand gave me the opportunity to work with many features that come standard with online blogging software. I developed tag clouds, post filtering, and the search functions based on the visual functionality that other blogs appeared to have. With this post, I'm going to explain how to make a tag cloud using PHP and CSS that can be implemented on any type of article- or post-based environment.

Most blogs that use tags allow multiple tags per post and tags being placed on multiple posts. The tag not only helps explain what the post is about, but also gives basic navigation based on tag for users interested in a specific blog category. A tag cloud provides the navigation with an additional feature: tags that are used more often in the blog are increased in font size, giving them more weight compared to less-used tags.

The first thing that you'll need is a PHP array of all your blog tags. The creation of this array is wholly dependent on your blog setup ...

read more »