PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

A First Look at Fuel

Note: This article was originally published at Planet PHP on 25 November 2010.
Planet PHP

There was an announcement a while back from Phil Strugeon and a few others (shortly after some issues came to light with a certain other framework) about a new framework they were developing that came to be called Fuel. According to their site, the goal is to be:

a simple, flexible, community driven PHP5 framework. FUEL aims to take the best idea's from a bunch of frameworks, throw away the aonot so gooda stuff, and create one awesome framework. It is provided under the terms of an MIT License, which means it's free to use in your personal, commercial or enterprise projects.

What's that? Why does the web need another framework? Well, to be honest, it doesn't - but there is one thing that Fuel has going for it. If you're one of the many CodeIgniter users out there, you'll feel almost immediately comfortable with it. Since the devs are CodeIgniter fans themselves, they've built a lot of the same feel into how Fuel handles your applications. Unfortunately, there's not a user guide for it yet, so I figured I'd share some of my experiences with it and maybe get you set down the road to fuel-ing your app (yep, that cheesy pun was required).

So, to get started, here's some simple installation instructions:

  • Grab the latest source from Github (this will probably change when they make releases)
  • Unpack the files into a web-accessible directory. Mine are in /www/htdocs/fuelapp
  • There's a /public directory in there - that's where you need to point the DocumentRoot to
  • Make sure that AllowOverrides is set to use .htaccess and that mod_rewrite is installed and working
  • Move the aoexample.htaccessa file over to just ao.htaccessa to make the rewrites work
  • At this point, when you visit the host for your site, you should get the aoWelcomea message
  • Be sure to aochmod 777a the app/cache and app/logs directories

That should get you started and have your basic application structure all set to go. In the basic layout, your application will live in the /app directory (makes sense, eh?) with the actual framework living in /core. As far as the three pillars of a MVC framework - they're in classes/controller, classes/model and views. There's also a config directory that houses the configuration files for your application.

Let's start with the controllers - here's an example snippet from the welcome controller showing you a basic controller structure:

output = 'Hello '.$this-param('name'); } }

This action is called at http://localhost/welcome/hello (obviously replacing the hostname with yours).

If you haven't seen something like the aousea call before, don't worry. It's just namespacing. The framework is PHP 5.3 only, so they can use fun things like namespacing and closures. In the example above, they load the Fuel\Controller namespace and extend the Controller\Base by default. There's some naming conventions to look out for in controllers:

  • Controller class names should be aoController_*a
  • They should extend Controller\Base
  • Methods should be aoaction_*a
  • Output pushed to the view belongs in $this-output

Something you don't see in the above example is how to interact with the view. You'll need to use the View class to get your data loaded into the right place. Here's an example of that:

public function action_index() { $arr = array('data' = 'test data', 'partial' = View::factory('test/partial')-render());$this-output = View::factory('test/index',$arr);}

If you're quick, you've spotted the aopartial viewa I've simulated. By calling that aorendera method on the view object, it returns the results as a string that can be appended. The parameter in that aofactorya call is the path to the view file. So, the string aotest/indexa refers to the file /app/views/test/index.php.

There's already some handy built-in helpers for the framework. It seems like all of them I saw were able to be called statically. So, for example - here's how you could use the Uri helper:

public function action_uri() { $detect = Uri::detect(); var_dump($detect); }

Oh, and one last thing I k

Truncated by Planet PHP, read more at the original (another 2934 bytes)