April 11, 2011

Introduction to Limonade-php

Before I begin I just want to note that this document is a work in progress. It requires version 5.3+ of php as it utilizies anonymous functions and it requires the use of limonade-php v0.5.1

Getting started with Limonade-php

Your first step is to simply download Limonade-php from GitHub. Make sure you grab the latest version (v0.5.1 at the time of writing this) and extract it. You’ll want to go into the lib directory and copy limonade.php and the limonade directory. The directory contains some utilities for limonade-php, but is not necessary. Infact, once your application is complete properly, I’d suggest you delete this folder and leave just the limonade.php file behind.

The standard first project

When it comes to programming, your first project is always Hello, World. So let’s not break that tradition. Create a new directory called “hello_world” and in it create a directory called “lib”. You can paste in the file and directory you copied earlier. Now let’s create a file called “index.php” and open it up in an editor of your choice.

Step 1: Setup

1 2 3 4 5 
<?php
include('lib/limonade.php');
?>

Simple enough, but if you visit that page in your browser, you’ll see that it doesn’t really do anything. So we’re going to add a bit more code.

Step 2:

First we’re going to say that whenever a user visits that page using a “GET” header, we’re going to display the text “Hello, World!”. In a nutshell, GET is one of the four recognized header types for REST implementations. GET is for retrieving information about a resource. For more information about REST, check out this post and combine it with this

1 2 3 4 5 6 7 8 9 10 11 
<?php
include('lib/limonade.php');
dispatch_get('/', function() {
    return "Hello, World!";
});
run();
?>

Did you just pass that function a function as an argument?

Why yes. Yes I did. It’s a new feature of PHP 5.3 that allows for anonymous functions. You’ll see the same thing happen in JavaScript all the time, so if you work with that, you should find it familiar. Essentially an anonymous function is just a function without a name. There is no way to call it without assigning it to a variable. So, by passing it to dispatch_get as an argument, it is assigned to a variable within limonade-php.

Finally, on line 9 we add the run(); command. This tells limonade-php to start.

Now if you visit index.php in your browser, you’ll see the text “Hello, World!”

Step 3: Profit

Now that you’ve gotten a taste of how easy it is to build something using limonade-php let me just say, that it really is that easy to build just about anything. Because of limonade-php’s adherence to RESTful principles it becomes ridiculously easy to build an API or a dynamic website, or just about anything in between. It even integrates very well with other libraries and components. It allows for rapid prototyping (I created this ([source])(https://github.com/AngeloR/Lemontrac) in only a few hours – including the time it took to learn limonade-php) and it has become an important part of my php toolbox.

Now what?

Well, it’s all well and good to display “Hello, World!” but it’s kind of useless to everyone who wants to build something useful. It hardly scratches the surface of what is possible with limonade-php. So, to properly show you what you can do with it, let’s build a very simple todo application. But with a twist. First we’re going to build a todo application API. Then we’re going to build a website that consumes this API using JavaScript and jQuery.

Stay tuned for part 2!

April 2, 2011

Lemontrac updates

Well it’s only been a few days since I released Lemontrac to the public but I’ve already got a slew of updates that I am planning for it.

Roles and ACL

The biggest of these updates is a complete overhaul of the user management system. The plan is to include role-based access control lists which will work pretty well I think. I thought about it and instead of shipping with pre-defined roles, the only role allowed will be an administrator role which will be able to do whatever they want. It’s up to them to create the rest of the roles and assign privileges to other users as they see fit. The more flexible it is, the better.

Sorting and Filters

Any data manipulation application should come with some excellent sorting and filters. The basic (alpha/last updated/created time/priority) will be implemented, but I am open to any other sorting ideas that people may have. Being able to easily get to all of these is a must, and so there will be some slight UI changes coming up.

Bug dependencies ##

Basically, some bugs appear because of a bunch of other bugs. A bug must be able to be marked as “dependent” on another bug. If that’s the case, that bug can’t be closed unless all of its dependencies are resolved.

Merging Bugs

Users are probably going to experience the same bugs. Being able to merge bugs (and notify the bug creator of possible duplicates) is a necessity to preserve the integrity of the application.

Email Notifications ##

This is something I completely overlooked until it was pointed out to me, but the ability to “subscribe” to a bug or project and be notified of it through future emails is a must.

You can count these as the features that absolutely have to be in place before Lemontrac can move to version 0.2 assuming that everything with work and switch to another OS don’t go terribly, you can expect April to feature version 0.2 and also a brief introduction into working with Limonade-php. I’d urge you to check out the website that is currently in place as it does have some great tutorials and examples, but incase you’re waiting for one, it is in the works.

March 29, 2011

Lemontrac bug tracker

Every year I try and make it my goal to really learn at least one web framework. I don’t need to become a master at working with it, but I need to know it enough to consider it one of the “tools” available to me.

This year I started trying to work with CodeIgniter, but then got sidetracked by various personal projects. That and the fact that most frameworks just feel too bloated to me. They keep trying to add on all these “features” and as nice as they are, they shouldn’t really be part of the CORE framework. They’re modules to enhance it. Not to mention that most frameworks have such a weird learning curve that it takes a long time before you’re comfortable with it.

That’s why I was pleasantly surprised by a new PHP framework I stumbled across called (Limonade-php)[http://limonade-php.net]. Limonade-php is a “micro” framework. It’s more or less one file with a few resources, a LOT smaller than any other framework I’ve seen. But it’s so ridiculously amazing that I knew I just had to work with it. Limonade allows you to build RESTful applications pretty much instantly. There’s almost ZERO learning curve and things just make sense.

For example, adding a new page is as simple as dispatch_get('/page/route','func_name'); But can be made complex by utilizing some handy features to allow for query parameters. dispatch_get('/page/:id/some/:resource','myfunc');

Of course being almost 100% RESTful compliant, you have access to methods such as dispatch_get, dispatch_post, dispatch_put, dispatch_delete all of can be mapped to the same path allowing you to REALLY build RESTful applications.

I was so impressed with Limonade-php that about an hour after playing around with it I started writing a tool that I needed for my daily work. It was a very simple bug-tracker allowing for multiple projects, bugs and users. It allows you to color-code projects, which immediately translate into color-coded bugs. And it was all done in a single file that is under 550 lines of code (not counting primarily HTML views and CSS).

So check out (limonade-php)[http://limonade-php.net] and if you like, take a look at (Lemontrac)[https://github.com/AngeloR/Lemontrac].