Juvely, Mark II

Posted by Luca on June 4th

Yay, at last exams are over, so now I can begin work on Juvely again! Well, not entirely true, as Im off to do some voluntary work for a week, but when I return its full speed ahead! Last week James and I had a chat and decided the best way for us to work would be implement the code and design seperately, until we are definate on what features we want, so yesterday I started work…

Originally we decided to create Juvely using the CakePHP framework because James didn’t know Rails much and we both planned to do the programming, in the end though it was me stuck doing it, and I grew to like CakePHP quite well. It is a nice framework, and clearly a lot of hard work has gone into it, but there are two things I don’t really like about it: PHP is an ugly language, and for some reason on our server is sssllloowww… Keepsy (written in Ruby on Rails) performs a lot more processing and intensive database queries than Juvely but seems a lot faster. Its not as if I have got it setup wrongly, they are both running as FastCGI applications under Lighttpd - you don’t get faster than that!

So anyway, yesterday I begin Juvely Mark II, in Rails. Just to give you an example of how I feel PHP is ugly, here are two identical statements in CakePHP then Rails. It is used to link the Tickets and TicketMessages models.


At the moment there is nothing really to show as I have only worked on it for about 5 hours, but I hope to add a much more Web 2.0 interface (I recently came across MoveMe, it has a really nice design but doesn’t look cheesy), and maybe even Google Gears integeration for offline usage.

Anyway, watch this space! For now here is a screenshot of what it looks like at the moment (not good…):

(P.S. This is also my first time posting with Wordpress 3, it looks very nice although it took ages for me to figure out how to attach an image as the form the ‘Insert To Post’ link is on doesn’t render correctly on Opera…)

Ruby, ruby, ruby, ruby

Posted by Luca on April 29th

Well firstly let me apologise for the lack of posts recently. One of the problems of being a student is that once in a blue moon you will have work to do….

Anyway, on to the content. The other day I had an idea for a new type of wiki to aid colaboration, it is early in the research stages and I don’t know how much will come out of it, but I decided to create a prototype, in Rails. This led me to question whether CakePHP was the best choice of language for us to use.

Originally we decided to use PHP because both James and I had used it extensively (James had only done a tad of Rails), I started creating a framework originally but then came across CakePHP so we decided to use that instead. In the end I did the majority of the programming as James was better at designing than me, and this didn’t take up as much time (he has work to do at uni :P).

So now lets get onto some of the problems with CakePHP, which are mainly due to it being PHP based. Firstly when you fetch a database record, rather than getting an instance of a class (as in Rails) you get an array. Although this doesn’t sound that big a deal it means you need extra code which decreases readability. Next up is how variables are sent to the view, in Rails you just create a global variable, where as in CakePHP you need to call a function. This again means extra code which decreased reability.

Another thing about models being classes, quite a major point, in Rails you can call functions in a model that affect the data in that instance of a class, in CakePHP you can’t (AFAIK) so you either have to add extra code to your controllers or write a function in the model that fetches the relavent data, updates and saves it.

Well, I think that is enough about why CakePHP isn’t as good as Rails, lets get on to the good stuff! If you don’t want to learn another language, and want a framework for PHP then CakePHP is an excellent choice! It supports both PHP 4 and 5, it is rather easy to learn (the documentation is nice and short so you can pick it up easily) and has a nice way of debugging (printing out SQL queries and the results at the bottom of the page, Rails doesn’t have this so you have to follow the oversized log files).

So what are we going to do about it? Well at the moment not much, we have got well over 150kb of CakePHP code and I don’t really feel like rewriting it all just yet. We shall wait and say if any major problems crop up, and if so give that big task of rewriting a go. Although it might sound bad, I shouldn’t think it would take too long as getting the views right is always the biggest challenge when implementing a new feature! If you are interested more about how CakePHP stacks up, here is a good comparison!

Javascript buffering with CakePHP

Posted by Luca on April 10th

Over time as I have AJAXified more and more of Juvely we have unfortunately had more and more little Javascript code blocks spread around the page. On the dashboard I think it was 4 or 5 codeblocks each with only about 3 lines of Javascript within them. I thought this was rather inefficient, so I was going to write a helper to store each block, and then output it all at the end, fortunately CakePHP has something that does just this built in!

The Javascript helper allows to cache all the code put through the codeBlock() function and then either output it at the end of the view, or include it from a seperate file. I decided to output it at the end of the view as this seemed more suitable for our uses. To enable this you simply need to include the Javascript helper in your controller and then put this somewhere in your view:

$javascript->cacheEvents();

The problem with this is that you have to put it in every view you want the Javascript buffered, and you might forget, so instead open up the code for the Javascript helper (cake/libs/view/helpers/javascript.php) and set the following variables at the top of the class:

var $_cacheEvents = true;
var $_cacheToFile = false;
var $_cacheAll = true;

Right, so how do you use it? Well simple, you just need to pass your code through $javascript->codeBlock() and tada! If like me you don’t current do this, you might want to do what I did to avoid horrible multiline PHP strings argg! I used PHPs output buffering functions to grab the code and then send it to the $javascript->codeBlock() function, I even made a nice little helper for it:

< ?php
class MiscHelper extends Helper
{
	var $helpers = array('javascript');

	function jsBlockStart()
	{
		ob_start();
	}

	function jsBlockEnd()
	{
		$this->javascript->codeBlock(str_replace(”\t”, “”, ob_get_clean()));
	}
}
?>

Then I just need to enclose my Javascript in the tags from the helper like so:


< ?php $misc->jsBlockStart(); ?>
alert(’This code is buffered!;’);
< ?php $misc->jsBlockEnd(); ?>

Feel free to share this, and if anyone has an account for the CakePHP Bakery to post it there!

Some light entertainment

Here are a couple of links to distract you from your real work for a few minutes.

First, a little video from the game The Punisher which some Aussie I know made:
http://www.loreindustries.com/flash/PunisherHill.html

Second, a nice little addictive flash game. Please take note of the warnings that it is very addictive and you will waste many hours playing it:
http://www.handdrawngames.com/DesktopTD/

Anyway, back to work on Juvely now, we have set a deadline for when we are going to start the beta, and it isn’t very far away! Eeeeek!

Next Page »