Giving a go to haxIgniter

Every time I come back to PHP I miss a compiler to save me from my stupid silly mistakes. Also, I have to say that after years of AS2, AS3 and haXe, PHP's syntax feels odd. And basically that's the excuse to try haxIginiter, a web framework for haXe targeting PHP and Neko.

[Warning, haxeIgniter is not a port of CodeIgniter, the PHP framework. Sure, ideas are pretty similar, but it's not a direct port]

As a rule of thumb, I like it. Although docs and code need further improvement, it seems easy enough to get your head around. Let alone it brings a compiler and friendly haXe syntax to the server. If you want to try it yourself, read the docs, starting at the intro and follow links from there.

I'll list some things that got me and might save you some time.

By default only works in the root of your server

In theory you should be able to make it work in any folder by tweaking Config.hx, but I got it working in the root and didn't try again.

Needs write permission on www/runtime folder

When I started testing on OSX under XAMPP I wasn't getting anything on the screen or Apache logs, for some reason. Finally tried in Ubuntu and got to the problem, you need write access folders in www/runtime.

Custom router

The router is the piece of code that decides the "translation" between URL and controllers. There're 2 by default, Basic and RESTful. Basic translates URLs to classes like this:

site.com/class/method/param1/param2

The RESTful follows the REST approach where:

site.com/controller/id > show(id, ?args)
site.com/controller/new > make(?args)
...

Ok, but what if you need more control than that? Well, for the time being you just have to roll your own. Create a MyRouter class implementing Router, add it to your Config.hx (about line 259 in 0.9.2) and you have full control over mapping URLs to controllers. See DefaultRouter.hx in haxigniter.server.routing for sample (as any other library, haxIgniter is installed in haxelib's path, find it running haxelib path or haxelib setup).

No obvious way of creating common + content views

haxeIgniter offers 3 different template systems. haxe.Template (default), Templo and good ol' Smarty. I'm not so sure that more is more in this case, especially since there's a low common denominator interface to deal with all of them, but anyway.

If you want to create a common + content view (common being html header, title, css and js links and content being each page's specific markup) you need to render templates inside templates:

[code lang="actionscript"]// Create content template and assign some sample value
var contentTemplate = new haxigniter.server.views.HaxeTemplate(this.config);
contentTemplate.assign('project', 'Wadus');

// Render content template and assign output to content var
// in main template. Main template needs ::content:: variable!
view.assign('content', contentTemplate.render('page.mtt'));

// Display main template
view.display('common.mtt');[/code]

No helper for linking assets into views

By default there's no helper to include assets in your view (js, css, images, etc). Something like:

[code lang="actionscript"]html.image('foo.png');[/code]

In theory, inside a view, that code would create a img tag with the right path to the foo image, working out what the application path is inside the server, etc. At the moment there's nothing like that, but you can set the base path in your html and then use absolute paths. Something like:

[code lang="actionscript"]// In your controller. Needs ::baseUrl:: in the template
var url = new haxigniter.server.libraries.Url(this.config);
view.assign('baseUrl', url.linkUrl() + '/');[/code]

[code lang="html"]<!-- In your view ->
<img src='/foo.png' />[/code]

--

So, there're a few gotchas and probably haxeIgniter is not ready for mass consumption yet, but I think it's a good start. I'm using it for building the next version of my website, so you will be able to look at "real" code soon. I'm using quotes here because the next version of my site is going to be very, very simple, so probably not the most complete haxeIgniter sample, but sample code nonetheless : )

Back to index