Welcome - my name is Nathan Davison, and I like to code stuff for the web. On this site you will find links and brief blurbs for my recent projects, as well as articles/tutorials I write relating to web development.
Using QUnit and Require.js to build modular unit tests
Using Dependency Injection and IoC in Laravel 4 controllers
I have never been a big framework user when it comes to PHP. While the language is not without its quirks and oddities that a good framework could help smooth over, I just never got around to really investing in a framework, as there is always a significant amount of initial effort needed to understand what the capabilities and limitations are, and whether or not it is truly suitable for a project. With that in mind, I typically just found it easier to write my own stuff.
Knowing what element was targeted in backbone.js View events
Mapping URL anchors to AJAX actions without a JS framework
PHP bcrypt hash a password with a logical salt
As I write this opening paragraph, yet another high profile website has seen its collection of user data, including passwords, stolen by a successful hack - in this case I'm referring to LinkedIn.com (but if you're reading this well into the future, another name can probably be substituted here as the latest big victim). Unfortunately, if you're a big enough target, being a victim of a hacker is usually more a matter of "when" than "if", but lets not allow LinkedIn to get off that easy - those passwords I mentioned? Yeah, they were stored as SHA1 hashes - without salting (let alone per password salting).
PHP sessions stored in a Mongo database
When it comes to coding user based websites and web apps, one of the concepts you'll no doubt have to comprehend is handling user sessions. If you're using a server side language like PHP, session handling comes about fairly easily - simply declare a session_start() on every refresh, and store and retrieve values from the $_SESSION array. By default, PHP will read and write this session data using the filesystem, but what if you want to move this functionality to a database?
Custom PHP MVC Tutorial: Part 1, introduction
If you code your web sites/apps in ASP.NET or Ruby and you're in the market for a MVC framework, you don't have to look very far - ASP.NET MVC comes with the latest Visual Studio, and Ruby's resurgence in the land of web dev can largely be attributed to the trendy Ruby on Rails MVC framework. What about good ol' PHP, though? True to its open nature, PHP has a bunch of popular MVC frameworks to choose from, each with their own assortment of positives and negatives to consider. However, before you go off on an epic Googling quest to pick one, have you considered writing your own?
Custom PHP MVC Tutorial: Part 2, URL mapping and index.php
One of the universal characteristics seen in MVC frameworks across platforms and languages is the structure of the URLs that the site/app works on - http://domain/controller/action/id - which is what we'll roll with here too. To do this for our custom PHP MVC framework, we'll need to utilize .htaccess URL re-writing with Apache.
Custom PHP MVC Tutorial: Part 3, Controllers
The controller classes in our custom MVC framework are the directors of our show. They get content from our models (writers?), and instruct our views (actors?) what to display. Even directors have orders to follow from above, however, and so do the controller classes in our MVC framework, in the form of a BaseController class they extend/inherit from.
Custom PHP MVC Tutorial: Part 4, Models
In part 3, we discussed creating the controller classes, and the example used (the Home controller) to show how a controller class might look didn't seem to reference a model at all. Technically, the model in that example was inbuilt into the method of the controller - not ideal. In this part 4, I'll cover how you may go about improving on that design with a concept sometimes referred to as Skinny Controller, Fat Model.