Book Image

Learning FuelPHP for Effective PHP Development

By : Ross Tweedie
Book Image

Learning FuelPHP for Effective PHP Development

By: Ross Tweedie

Overview of this book

<p>PHP frameworks have been around for a number of years. FuelPHP was one of the first frameworks built for PHP 5.3. It makes use of more advanced features of the language to allow you to focus on delivering features and code for your projects. FuelPHP allows you to quickly build prototypes using scaffolding and command-line tools, thus allowing you to concentrate on the fun part of trialling ideas and concepts.</p> <p>This practical guide will show you how to use FuelPHP to quickly create projects more quickly and effectively. You will learn everything you need to know when creating projects with FuelPHP, including how to adapt the project as ideas change and develop.</p> <p>This guide is packed with several tutorials that will help you to build a powerful and engaging application, and in the process you will learn more about FuelPHP. This book explores how to install and build a FuelPHP project in a step- by- step approach.</p> <p>Starting with an exploration of the features of FuelPHP, this book then delves into the creation of a simple application. You will then move on to scaffolding your application using the powerful FuelPHP Oil command-line tool. Next, you will be introduced to packages and modules, and also cover routing, which allows for cleaner URL structures.</p> <p>The book concludes with an introduction to the PHP community.</p>
Table of Contents (14 chapters)

Routing


As with other frameworks, FuelPHP has fairly extensive routing capabilities. In this section, we will run through the basics.

Firstly, there are a couple of reserved routes; they are: _root_ and _404_. The _root_ key is used when there is no URL specified; for example, the home page or root page. The second (_404_) is for when the requested content controller or view can't be found.

The routes exist in the config folder of the application in a file called routes.php. Let's load the routes.php file from the following path comprising the following code:

[rootOfProject]/fuel/app/config/routes.php

<?php
return array(
    '_root_'  => 'welcome/index',  // The default route
    '_404_'   => 'welcome/404',    // The main 404 route
);

As you can see from the routes configuration file, the routes are stored as an array. The key on the left is matched to the URL and then the items on the right are executed by FuelPHP. This is fairly straightforward, but can lend itself to complex URL and...