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)

Tasks


Sometimes, we will want background processes, periodic tasks, or maintenance tasks to occur. This is where FuelPHP tasks come in handy. They can be run via the command-line tool, or set up as a periodic task on Windows, or cron job on Mac OSX and *nix. They can call upon modules and other classes just like controllers can.

Tasks should be placed in the fuel/app/tasks folder and, by default, only a run() method needs to be defined within the class. If you need other methods, these can be added in the usual way for PHP classes.

The tasks are called using the Oil refine command. FuelPHP comes with an example task called robots and will be included in the fuel/app/tasks folder.

To call the main method of the robot task, you can run the following command:

$ php oil refine robot

The run() method in the robot task has a variable defined, allowing you to pass a string via the oil refine command. Typing the following command line will change the message in the task:

$ php oil refine robots "Kill...