Using Laravel: first impressions of a PHP framework

laravel logoOur team recently faced a typical (PHP) developer problem: build a simple app in a few days that’s good-looking and feature-rich enough to convince your customers right from the start that you mean business. After all first impressions really do matter.

We wanted to find a PHP framework that would let us develop rapidly, while also giving us long-term scope for rich development on a large project. We might also want to use the framework on other projects too.

A couple of days of searching, forrsting, and general trawling through the internet and we came up with a couple of prime candidates for a PHP MVC framework – FuelPHP and Laravel. They are in fact rather similar. Children of 2011, both are based on the hugely successful CodeIgniter. They improve on their mentor in a number of ways – often specifically PHP 5.3 (and 5.4) related ways. The heavy use of namespaces and closures are things which spring to mind.

We particularly liked Laravel early on because of its clear documentation, and a healthily active community of developers working both on the core and a raft of handy plugins (aka bundles). We also found some particularly good tutorials by Dayle Rees who has even published an ebook called Code Happy with Laravel

We found a great little CRUD app on GitHub which seemed a good way to get started with Laravel. It uses twitter bootstrap too, and looks great!

So we went for Laravel.

Simple (and fun!)

The first thing that struck us about developing with Laravel was how simple it was. Our usual experience with big frameworks (you know which ones I’m talking about…) is that you end up spending about a week/month grappling with obscure YAML config settings, unhelpful helpers, fussy syntax, partially documented classes, and a general sense that the framework isn’t in the end really saving you a lot of time or effort. We just didn’t find that at all with Laravel.

One of Laravel’s selling points is that it brings the fun back into PHP development. And you think “yeah right, well they would say that wouldn’t they”. And other things along those oh so cynical lines.

But our experience was that it really did seem to make development more fun. Laravel provides just enough built-in features that you can focus on the more interesting parts of your app without having to worry too much about the boring basics.

So what are these features?

Eloquence

Laravel uses its own ORM, called Eloquent. This is based on PHP ActiveRecord, although I’m not clear at this stage how exactly it differs. But it does work well – and simply – while allowing for more advanced features like eager loading.

Unless you have a really crazy schema the chances are Eloquent will work well for you. Certainly the schema for our project is somewhere in between basic and complex, and we’ve not yet come across any gotchas.

A project I worked on a year or so ago ended up using key-value storage in a MySQL db. It wasn’t an easy decision. If you’ve ever tried key-value storage with a relational ORM you’ll know what I mean. Mercifully life doesn’t have to be that cruel, and if your friendly neighbourhood sysadmin is having a good day things like MongoDB and Redis are there and ready to serve. My point being? Laravel has Redis support built in. How nice.

You can also build your own queries with Laravel’s Fluent Query Builder, or if you really need to you can always just write those SQL queries in the raw like mama used to make.

Laravel does come with a handy db migration tool too. It’s not super-sophisticated, but it is useful for running (and rolling back) schema changes. Added to this is the Schema class, which basically lets you very easily create database structure without coding any native SQL.

Bundles

An important feature of any framework is a community of developers who contribute extra functionality to the core through some form of plugin system.

Laravel is no exception. It has just over 80 “bundles” (when I started thinking about writing this post 2 days ago it had 80. Today it has 82. Crazy!) ranging from a scaffolding tool called Bob to a very simple profiler bundle which adds the PHP Quick Profiler to your site.

Bundles are hardly at the volume of symfony or Drupal plugins/modules, but it’s impressive work for a framework that barely existed a year ago. Also I’d say from my experience developing with WordPress and Drupal that it’s far better to have a few well-maintained plugins than a sea of plugins that worked really well a year ago in version 1.0

The rest

I don’t want to downplay the many other features that Laravel has, but there’s little point in describing them in detail here. If you want a really nice outline then take a look at the clean and clear Laravel docs. Basically Laravel has a bunch of features that are pretty much what you’d expect from a framework: form helpers, caching, session tools, authentication, security features… You know the kind of thing, and it’s all good stuff.

What we did

Our goal for sprint 0 (we’re an Agile team you see) was to build the beginnings of a CRUD app to manage University course details. It needed forms for editing courses, LDAP authentication, some role provisioning, and importantly a versioning system that would track all edits and allow rollback to earlier versions of courses.

We (3 developers) managed to get from absolute 0 to beyond our sprint minimum viable product in about 40 developer-hours. Most of that time was actually spent planning how the app would work, working out the data model, and generally making it look nice. We spent almost no time at all worrying about how to get Laravel working for us. The whole thing really was great fun!

And on top of that our customer was really happy with the result. We love happy customers!

Nice-to-haves

We enjoyed using Laravel. That doesn’t make it perfect, so here’s a couple of things that would be nice. I suppose instead of sounding like I’m moaning too much I should just git in there. Anyway…

  • Documentation. While Laravel’s documentation is really nice, there’s kind of a gap between the getting started stuff and diving headlong into the API (which is itself well commented actually). Laravel is still really young, and the fact that the documentation is as good as it is says a lot for the core developers’ commitment to clarity.
  • Behat. Laravel really suits Agile and BDD. It would be lovely if Behat/Mink were included out-the-box in the same way unit testing is. To be fair it’s not hard to get Behat tests up and running alongside Laravel. But still… it’d be a really nice feature.

Conclusions

If you’re looking for a solid, fresh, new, simple, and well-supported PHP framework then you could do a lot worse than choose Laravel. In fact you couldn’t really do a lot better. It’s lightweight enough that it doesn’t get in the way of your planning and development work. But it does still offer plenty of structure and handy built-in features.

Report post

Welcome to Justice Addison, our new Web Developer

Justice AddisonWe would like to welcome Justice Addison to the Web Development team. Justice will be moving from his role as Senior Web Developer (Part Time) in the Requirements and Solutions team on 14th May.

Justice has recently completed an MSc in Computer Security and also holds a BSc in Computer Science, both from the University of Kent.

Justice brings a number of different skills with him, including PhP, Java, HTML and CSS as well as knowledge of the Pantheon templating system. He has been involved in a number of successful web sites in recent years, including the Kent Health Portal and the Text and event in early modern Europe website and is keen to put his skills as a Certified Scrum Master to use on projects in the Web Development team.

Justice is enthusiastic about web development and security, but also has a keen interest in music and sports. He has recently joined the Territorial Army and is preparing for his two week Trained Soldier Course (Bravo) in June.

Please join us in welcoming Justice to the team!

Report post

Welcome to Alex Andrews, our newest Web Developer

Alex's desk

We would like to welcome Alex Andrews to the Web Development team. Alex joins the team on Monday 5th March 2012.

Alex brings a range of technical skills to the post, including PHP, HTML/CSS, Ruby and Javascript. He has spent the last year working as a Web Developer at various companies and is the co-founder of Records on Ribs, a Creative Commons record label.

Alex has recently completed writing a PhD in Theology and Religious Studies at the University of Nottingham and also holds an MA in Philosophical Theology and a BA in Theology.

Please join us in welcoming Alex to the team!

 

Report post

Implementing scrum in a multi-product environment

One of the challenges we have faced since the start of our journey of implementing scrum, is how to be true to the scrum process whilst operating in a multi-product environment.

Scrum is built around the principles of ongoing sprints with a product backlog involving a single product, or at least, a single product owner. In this environment, the process of build-fix-improve is made easier by the fact that there is always the next sprint right around the corner, with a product owner as an integrated member of the team.

In our team, we have responsibility for a multitude of products, encompassing a number of product owners across a number of organisationally and geographically disparate departments. The product owners are not able to take much time out from their normal duties to sit in with the development team, and sprints on a particular product can be separated by many weeks or even months.

So, what do we do? The ultimate answer is I suspect still unwritten. However, for the moment we ensure that we are at least able to chain a few sprints together back-to-back, try to ensure that each product is slotted into our sprint cadence sufficiently in advance to be able to book required time with the product owner, and ensure that the last sprint in a chain is structured in such a way as to allow for the fact that the subsequent release will be the last for a while. Any bugs after that point are slotted into our support and maintenance time to be treated the same as the rest of our support work.

One challenge we still face is dealing with the effects of the planned slots having to move due to changing organisational or emergency requirements. This has led to us having to carefully negotiate the prioritisation of various projects with each Product Owner, but this has been, so far, a very amicable and positive experience.

One of the impacts of splitting sprints is that of context switching. We need to find the right balance between being able to shift things around and finding enough chains of sprints to get back up to speed and productive on a product. I suspect I will blog more about this as the year goes on!

Report post

WordPress 3.3 and blogs.kent

Wordpress logo

WordPress 3.3 is almost here! Currently at Beta 4, a release candidate is apparently very close. We’ll hopefully be upgrading blogs.kent from 3.2.1 to 3.3 sometime in December, if the normal WordPress release timeline is anything to go by.

WordPress 3.3 brings with it several new features and tweaks for blogs.kent users. One of the nicest in my opinion is the much improved drag-and-drop media tool, to let you add images and video to your blog post really easily. Another death-knell for Flash, the new media uploader uses HTML5 (and Silverlight, which seems a strange choice, but I guess they wanted to cater for the maximum number of people?)

They’ve also refined/changed the admin bar (again), so expect things to be a little differently laid-out.

All in all, WordPress is shaping up to be a really great tool not just to blog about stuff, but to build up a nice little website for yourself.

Until we get 3.3 up on blogs.kent, you can read a list of some of the key new features in a bit more detail at wpmu.org.

Report post

Overview of Sencha Touch and the Kent Mobile App

University of Kent mobile app icon

It took a while, but we got there… The University of Kent finally has a mobile web app! You can access it on an iOS, Android, or Blackberry device (or WebKit if you’re not on a mobile).

We started work on our mobile web app back in July. It took us about three weeks of fairly intensive investigation, trial, error, dead-ends, and finally a solution we were really happy to work with, and which we felt could be a solid framework on which to expand the functionality of our mobile app.

So what kind of functionality did we want from the app?
It’s important to realise that in its initial state the app doesn’t provide students with anything that they can’t already access online on a desktop browser. The key difference is that we wanted to provide a range of information to students on-the-go, all in one place, and in a format that’s easy to use and access on a mobile device. The key things we wanted to address in the early stages of the app were:

  • Timetables
  • PC availability
  • Campus maps
  • Mobile device setup help pages
  • Getting started pages
  • Feedback form
  • News feeds
In later stages the plan is to provide other information, such as link ups with campus restaurant menus and services, Moodle, the Student Data System, and the library online catalogue.
JQuery Mobile investigation
JQuery Mobile LogoAn early candidate as a development platform for our mobile app was JQuery Mobile.
JQuery Mobile allows developers to build a mobile web app using only HTML5, assigning attributes to tags to provide functionality and a mobile look and feel. As a development environment it looked promising:
  • Simple.
  • Quick to build a basic app.
  • Works across a large number of devices.
So we spent a week or so building a prototype app using JQuery Mobile. It was ok, but we found a few issues:
  • Not a programming language, so it didn’t feel powerful enough for an extensible MVC framework to allow a range of functionality.
  • Slightly clunky transitions (at least in beta). User experience sort of ok.
  • Limited ability to modify the look and feel of the app.
  • Doesn’t feel like a native app – eg no gestures or swipes.
  • Will only ever allow a web app, rather than an app in iTunes etc.
The move to Sencha Touch
Sencha LogoThe negatives of JQuery Mobile weren’t massive, but were enough for us to feel we should at least take a look at a viable alternative.
We chose Sencha Touch, a mobile app framework based on the the Ext JS javascript framework.
We spent a few days building another prototype with Sencha Touch, and found it had pretty much the converse pros and cons from JQuery Mobile:
Pros
  • entirely in javascript, so is powerful enough for an extensible MVC framework to allow a range of functionality.
  • Smooth transitions and user experience.
  • Ability to modify the look and feel.
  • Does feel like a native app – native gestures, swipes, etc.
  • Can potentially be wrapped up in PhoneGap for AppStore or Android Marketplace.
Cons
  • Steeper learning curve that JQuery Mobile.
  • Requires more effort to build even a basic app.
  • Only iOS, Android, and Blackberry are supported.
  • Slower initial loading time (although faster once the app has loaded up in the device).
So, we felt on balance that Sencha Touch offered the best solution for developing functionality in the long-term, as opposed to getting something simple up and running quickly.
Summary
  • We looked at JQuery Mobile. Seemed promising.
  • We looked at Sencha Touch. Seemed even more promising.
  • Sencha Touch has bit of a development learning curve, but it is powerful and fast.
  • Sencha Touch offers only 3 compatible mobile OS (iOS, Android, Blackberry). However these three systems cover the vast majority of smartphones used to access www.kent.ac.uk currently.
  • Our app may still be a little rough around the edges but we needed to get something out there. There is still a lot of work in the pipeline…

Report post

University of Kent events system

The University of Kent has long needed a centralised system of creating events and displaying them on the main website. So a major piece of work we’ve been engaged with for a while now has been to build an events calendar system.

It will go live on 7th November at www.kent.ac.uk/calendar (currently restricted access)

Because you won’t yet be able to see the system working, I’ve included a few screenshots below. (They also help make this blog post look prettier.) Please do note that the events in the images below are just for testing purposes! So don’t rely on them being accurate until you seen the actual live system up and running at www.kent.ac.uk/calendar

The main calendar page. Notice the calendar view to the right, and the category listing to allow users to filter the event types they see.

Centralised and federated

A key feature of the new system is that it will allow users to add their own events to display on their own calendar sites, as well as submitting those events for inclusion in the central university events calendar. Once events have been created, approved, and marked for publishing, they then appear on the appropriate calendar on the university website. This could be on the central /calendar site, on a departmental site, or both. This is important, because for the first time users around the university will be able to manage their own events while allowing them to be easily reused elsewhere on the website.

An event detail page. This is just a test event, so admittedly the details are a bit sparse. But you get the general idea.

Blogging events?

Some of you might be thinking “I have a wordpress blog and that has a really nice events plugin”, etc, etc. Good for you. Well, we did consider that as an option, but while such plugins are great, they just didn’t allow the power and flexibility we wanted for this product. In particular, they typically lack the ability to have a range of events calendars for separate centres and departments at the university, each of which could offer up event suggestions to the central university events calendar. WordPress-like events plugins work really well for small-scale, localised requirements, but less well across an entire organisation.

Sharepoint administration

The centralised/federated requirement entailed a relatively rich permissions system for administering and creating events. One which would know as soon as you log in who you are and what group, team, department you’re in, and would control the level of access you have for creating and approving events.

This got us to thinking about Microsoft Sharepoint. It’s used across the university as an intranet and document sharing tool. It integrates with our managed desktop PCs so it knows who you are and what you do. In fact it already has a bunch of powerful permissions and workflow tools and settings built in. What if we were to use that as the admin area for creating and managing events?

What indeed. After a few weeks’ playing around with the intricacies of Sharepoint, RDFa, SPARQL, ARC, our own Pantheon publishing framework, and a range of other technologies, we decided that it would work! So started a phase of agile development (more on this below) to produce a Sharepoint-based admin interface and a Pantheon-based frontend interface.

Sharepoint main calendar admin screen. After an event has been created, you can click on it in the calendar to view or edit its details.

Slurp!

We decided after some initial testing and trials that the best way to hook up Sharepoint with Pantheon was to build an intermediary system which pulls data out of Sharepoint and put it into a relational database – in this case MySQL. We gave this intermediary the not unimaginative title of “The Slurper“. The Pantheon frontend code would then use the MySQL db as its data source directly. Nginx caching would then help sort out any performance issues that might arise from using direct db calls.

The slurper was actually key to the whole process because it had to be lightweight enough to run very frequently (every minute) to allow the frontend event listings to keep up to date with backend edits. Obviously with potentially thousands of events in Sharepoint, it just wouldn’t be practical to pull out every single event every minute into a database without slowing Sharepoint down for all the other tasks it has to perform in our organisation. The trick then was to make sure the only events to get pulled out would be those that had been added, deleted, or modified since the last update a minute ago. Also, in case a lot of events got added simultaneously the slurper was throttled to pulling 10 events a minute. Although this means it might get behind when lots of new events are added, it should still catch up with itself fairly quickly, and it would never put unrealistic demands on Sharepoint.

Agile scrums

I mentioned the term agile development above. I really don’t want to go into the details of agile methodologies here, but I do want to mention it briefly because I feel it was important to the development process for the events calendar and what I feel is its overall positive outcome.

Suffice it to say that the events calendar product was our first foray into the world of an agile project management methodology – specifically Scrum (or perhaps more accurately Scrum-but). The idea is that we work not on projects but on products; we work in very carefully timeboxed two-week sprints; and we work with the aim that at the end of each sprint we deliver the most important new features of the product at that time.

Although we were learning a lot as we were going along, the end result is I think a much more efficient process of producing and maintaining a product. Agile does not mean easy. It does not mean “make cool stuff up as you go along”. It’s a very tightly controlled and transparent approach. But it works very well when done properly, and you have good buy-in from your customers.

Future plans

The initial deployment of the events calendar will be relatively limited in scope. Once we’re more confident that it’s all working well and – most importantly – easy for people to use, it’ll start to get opened up to a wider audience. As with all products developed in an agile framework, they are never fully completed, and development on the product is always ongoing.

 

Report post

Sublime Text 2: A new IDE

I’ve recently been trying a new IDE and I’ve been so impressed I’ve decided to spread the love. Sublime Text 2 is cross platform (Windows, OS X, Linux) IDE, it claims to be a text editor but to refer to it as such is to do it an injustice, whilst it might not provide a fully integrated environment it is defiantly a developer tool rather than just a text editor.

NOTE: The views reflected in this post are solely my own and in no way reflect the views and opinions of the University of Kent. The University of Kent does not endorse any of the mentioned products.

NOTE: Apologies, I develop on OS X and therefore this review is from that perspective, if you are on Linux or Windows replace CMD shortcuts with CTRL and you should be fine.

Cost

Sublime is $59, more than TextMate ($44.85) but less than Coda ($99), and obviously significantly more than the many free options out there, Eclipse being the most obvious. However the trail is unlimited, you just need to dimiss a prompt to buy every so many saves. Personally I think Sublime is well worth the $59, however I’m going to put up with nagging until I see what Coda and TextMate have to offer in their upcoming V2s (if they ever come out).

Cool stuff

Hot exit

I’m not sure if this is cross platform or just tied into Lion’s resume API but its awesome, quit Sublime and the next time you open everything will be as you left it, including the scroll position (of the current file, would be nice if it was every file).

It will even keep any changes in unsaved files!

Mini map

I’m not sure how useful this feature is but it is cool, its basically a thumbnail’s width view of the current file on the right side of the window you can use to scroll the file.

Command menu, CMD+SHFT+P

This adds a little confusion as some commands are in this searchable menu and some are in the application menu and some are in both. But it works really well for when you can’t remember the shortcut for some thing (or there isn’t one).

Goto anything menu, CMD+P

This is possibly the single coolest feature:

Sublime Text 2 has Goto Anything (Ctrl+P on Windows and Linux,Command+P on OS X) to quickly navigate between and within files:

  • Type part of a file name to open it. Files can be open files, recently closed files, or files in the project. The fuzzy matching is fast and intelligent, providing instant-as-you-type navigation on 50,000+ file projects.
  • Type an ‘@’ character, and start browsing by symbol. Type ‘#’ to search within the file, or ‘:’ to go to a line number.
  • Combining these together, for example, “tp@rf” may take you to a function called “read_file” within a file named “text_parser.py”. Similarly, ‘tp:100′ would take you to line 100 of the same file.

The Goto Anything panel previews where it will take you as you type, loading files asynchronously in the background. You can use this to quickly look up the definition of a function, pressing escape to go back.

The various within-file symbols operate on the current file if typed alone, for example, “:50″ will take you to line 50 of the current file, and “@” will browse the symbols of the current file. There are key bindings to open the Goto Anything panel with these pre-filled, for example, Ctrl+R (Command+R on OS X) will go directly to the list of symbols in the current file.

Multiple select

You can insert your cursor at multiple points in your file, just hold down CMD and click to create a new cursor, if you CMD+drag you can create multiple selections, if you CMD+double click you can select multiple words. To create multiple cursors across multiple lines hold down CMD+ALT and drag your mouse across the lines you wish to place insert points at. Typing will then occur at each of the cursor points.

Snippets

These work exactly like in TextMate (in fact Sublime support TextMate tmSnippet files) however having not really used TextMate before I find these very cool, and much much better than Coda’s snippets. I found it takes a little editing of distributed snippets to get them insert code to match your personal preference but its defiantly worth it.

They work by pressing tab after certain tab trigger key words, for example if I type foreach and press tab in a php file I will get something like

foreach ($variable as $key => $value) {
	# code...
}

pressing tab will then move the selection through $variable, $key, $value and #code in turn.

If I type foreach and press tab in a php file but outside of php tags I will get:

<?php foreach ($variable as $key => $value): ?>

<?php endforeach ?>

There are tonnes snippets for loads of languages, and you can always supplement them with your own.

PACKAGE CONTROL

This package will make it much easy to manage some of the packages mentioned below, grab it here.

Autocomplete + SublimeCodeIntel package

Sublime comes with word completion (based on other words in the file) but the SublimeCodeIntel package improves it ten fold, you can install it using the Sublime Package Control.

I’ve been using it with PHP, which given its loosely typed nature, can be difficult to autocomplete but CodeIntel seems to do a pretty decent job.

Open recent files

You know when you close a tab in Chrome you can do cmd+shft+t and it opens again (well you do now) this plugin introduces the same functionality to sublime.

SublimeLinter

Checks the syntax of your files as you type, or on a save/open.

Soda theme

Sublime isn’t the worst looking IDE I’ve seen but this theme certainly improves on what is already there. In addition to installing via Package Control you will also need to enabled by adding:

"theme": "Soda Dark.sublime-theme",

to Preferences -> Global Settings – User

Standard stuff

Find, find & replace, Find in project

Pretty standard stuff here: regexp supported, case insensitive and sensitive, highlight matches, find in open, find in dir…

Project

Create Sublime project files to easily only directories and settings for them.

Layouts

Split file vertically, horizontally or both.

Syntax Highlighting

Sublime supports TextMates tmLanguage files, and tmTheme files so even if your using an obscure syntax if there is a package for TextMate you can use it in Sublime.

Could do better

The main weak point for me is the file manager, its perfectly good for finding files but it’s less good when it comes to tasks like creating, renaming and moving files and folders. Most of the functionality is there but the UI behaviour doesn’t match up with long established patterns that we are all used to in programs like Windows explorer and Finder. Moving files seems to be missing entirely.

Report post

BBC sprint board looks familar

A few days ago the BBC internet blog published a blog post about designing the new BBC homepage. The article itself is worth a read but what caught my eye is the photo of their sprint board.

Tasks for the BBC Homepage developers are tracked on the team sprint board

Tasks for the BBC Homepage developers are tracked on the team sprint board

The columns are very similar to ours:

Our current tasks on the team sprint board

Our current tasks on the team sprint board

We don’t have a “not started” column instead we have a massive backlog from which the top tasks are taken and somewhere down the list is a commitment point for the current sprint. But everything before this point is equivalent to the “not started” column.

We also have a single “QA” column rather than a “dev check” and “verify” column. I’m not sure if the “dev” they are referring to is the developer who implemented the task and the “verify” is another developer or the “dev” is a different developer doing peer review, and then the “verify” is the product owner (I suspect it is the later). Our requirements are slightly different since as we can’t rely on our customers being around to verify our progress on a day to day basis.

Our “In progress” column includes a dev check by the developer who implemented the task and a peer review (currently informal chat depending on the task). The “QA” is for a separate developer to test and provide quality assurance.

“Done” for us then means that its on the demo server and ready to be shown to the customer at the end of sprint demo, so I guess our “done” is equivalent to their “verify”. Since we often can’t get verification from the customer until the end of the sprint it makes having a distinction meaningless within a sprint, since nothing can ever be done.

I might suggest that we introduce a separate column for “dev check” which is a dedicated peer review column.

I’ld love to see a better photo of the second board and a blog post about their agile processes.

Report post