Articles and Posts - Page 1
Using QUnit and Require.js to build modular unit tests
It used to be that a web server was responsible for the smarts that went along with converting data into HTML for the browser. Remember those days? While I may be exaggerating the matter ever so slightly, it seems increasingly more and more common these days to see Javascript and the browser itself take on all of the work involved in converting raw data into HTML markup, leaving backends to solely concentrate on storing and retrieving the data in formats more suitable for software, like XML and JSON.
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
I've recently had a project that I have been slowly progressing for a while demand more of my attention, and it's a prime candidate to finally familiarise myself with backbone.js given the heavy javascript usage involved. So far, so good - despite initial confusion regarding just what advantages it would offer, backbone.js certainly seems to be delivering on its promise of an alternative to unstructured jQuery mess. However, just as things seemed to be going smoothly, I came across a rather frustrating roadblock - how on earth do I know what element was targeted in a backbone.js View's event handling function?
Mapping URL anchors to AJAX actions without a JS framework
There is no doubting the dominance of AJAX heavy webapps/websites in recent times when it comes to looking at what is working well on the web - done right, they are easy and powerful to use. However, from a developer's perspective, it can be difficult to design asynchronous events and actions within the framework users expect from a browser - expectations such as being able to traverse actions via the back and forward browser buttons, and being able to represent current event state in the webapp via a URL. To address this issue, many Javascript frameworks and packages have been developed, some of which are exceedingly popular, but in this article I will cover a quick way to introduce these capabilities to your AJAX driven projects without requiring you to conform your entire Javascript codebase into a 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.
