Getting started with Fuel

So,
I’ve been working with the Kohana Php Framework for a while now, and even though i really like it, I’m getting a little bit tired of having to run Migrations with every new minor release due to backwards incompatible changes they keep making.

Because of that i’ve been looking into the Fuel Php Framework a bit and so far i like what i see. So i’m going to try and port my current Webapp over to Fuel and try to document the process of this right here. Assuming that i find enough time to complete that Task and that i won’t get tired of writing it all down, this might be a useful resource for anyone trying to get started with Fuel.

Well then, lets see how this goes.

Minor Setback

Oh my,

I feel like having a deja-vu.. I realized yesterday that there is a new version of FuelPhp out 1.1 RC, promising that the API will be in lockdown starting on this release, so i decided that i try and update my 1.0 version to this.

Luckily i checked everything into git before i copied the update over, and of course there were TONS of changes, which makes sense at such an early stage of the Framework.
Now my Haml Parser changes aren’t working anymore since apparently the View class has changed. So i’m going to have to dig through all this andmake this work, then i’ll continue on the Migration Log.

Gna!

I suppose i have to get my HamlPHP Parser changes into the general Release so it’ll be taken care of when changes like this are being made.

 

 

Using Haml with Fuel

One thing i grew to love over the past year or so, is Haml.
I got so far that when i have to type raw HTML for other projects i’m working on it makes me frown.

So to jump right into it. Fuel doesn’t have direct Haml support, but there is a parser package which claims that it supports Haml, however i never really got it working right. Also i wanted to use sniemela’s HamlPhp Parser instead of PhamlP, because its cleaner, faster and supports standard Haml syntax.

So i had to modify Fuel’s Parser package a little bit in order to make it work with the new Haml Parser. I havent checked but i can imagine that my changes broke other templating parsing in that parser package, but since i only want to use Haml anyways i don’t really care. Maybe if i find the time one day i will test them all.

You can find and download the modified Parser Package here: https://github.com/codeho/parser.
You will need to download sniemela’s Haml Parser here: https://github.com/sniemela/HamlPHP and put it into the vendor directory within the parser package, which you hopefully put under fuel/packages.

The rest is pretty self explanatory, call your views like you’d always do, just add .haml to the filename of the view when you call it.
Make sure you got a chache directory and its writable for the Php user and you’re good to go.

 

Kohana i18n in Fuel

Kohana::i18n == Fuel::Core::Lang

Getting your Kohana i18n stuff migrated to Fuel is actually very easy.

First of all copy your old language translation file into lang/[countrycode], for example: lang/de/german_signup.php

In the general config (config/config.php) you have to set the language, which determines in which of the directories under ‘lang’ Fuel will look for the file. e.g. ‘language’  => ‘de’.

Then you have to load this somewhere using Lang::Load(‘[filename]‘);, for example Lang::Load(‘german_signup.php’);

In this particular Project I’ve put it within the before() function of my Base Controller, that way i don’t have to worry about it.
Right now i don’t see any sense in having a separate language file for each controller, because of this i can load it within the base controller of everything. Who knows, maybe i’ll change my mind about this later, but not just yet.

To Load  a string:
I18n::get(‘firstlevel.secondlevel’);
becomes
Lang::line(‘firstlevel.secondlevel’);

That’s pretty much it. easy huh? :)