This is an outdated version of PHPasap. Please visit http://phpasap.com/docs for the latest version.

Helpers (Custom functions)

Classes can be autoloaded using the namespace and directory naming convention. But what about functions? You might need a bunch of functions that are available on every HTTP request. PHPasap makes this easy for you with the use of helper files.

Adding a helper file

In app directory there is a directory named helpers. Any php file inside this directory will be included by PHPasap before calling the controller. So you can create any file, lets say common.php in this directory. This file is expected to contain only functions and no classes. Since this file will be included by PHPasap any function you write in this file will be available throughout the application.

Below is an example helper file. You can name you file anything.

app\helpers\common.php
function abc() {
    //rest of the code
}

function xyz() {
    //rest of the code
}

So whenever you need to add a new function you may add to this common.php file or you may create a new helper file in helpers directory.