Fork me on GitHub

Nibble Development

Nibble Development

PHP classes and libraries for developers

Creating applications and actions classes

Pointing to the application

Packaged in with the Nibble PHP Framework is a .htaccess file. This file, for which most of the credit goes to Ramesh Tabarna, looks in the web directory for any files that satisfy two conditions.

The current URL is searched for the value after the first “/” and before a second if it exisits excluding the http:// and the domain name.

If a value exists and the value matches the name of a file in the web directory, the first criteria is satisfied. For example, if http://nibble-development/admin is the URL then the value is “admin” and the system will search for a file called admin.

The file that is searched for must be a PHP file, this does not mean that the contents are searched, but rather that the file must have the .php extension.

If a match for the URL value is found, the PHP file is loaded. If not, the index.php file is loaded by default. In the PHP file the application constant “APP” is set up, the config.php file included and the initialise class instantiated:

When creating a new application, pointing to it is as simple as making a new file in the web root with the name of your application, and defining the “APP” constant as your application name. Essentially copy and paste the above into a new PHP file and change “admin” for the name of your choice. For logical reasons the application name is the same as the file name in the example above, but that does not have to be the case. Feel free to call the file Peanutbutter.php and the APP constant Jelly if you so desire, no judgement here!

Creating an actions class

  • A Bite can have as many actions classes as necessary. Each actions class is loaded for only one applications, thus three applications (admin,member,frontend) requires three different actions classes. There is an exception to this rule in the Ajax actions class, this class runs all of the Ajax methods for the whole Bite. Action classes in the Nibble PHP Framework have three mandatory properties that must be of a certain type or formats:
  • Name: The actions class must be named in a set way, actions.appname.class.php where the only variable is “appname” which corresponds to the name of the application (admin, member or frontend etc).
  • Namespace: The actions class must have a namespace that consists of the Bite name followed by the application name. For example, in a Bite called User, the admin application actions class would have the namespace:

The introduction of a namespace allows multiple Actions classes to be loaded (using require or include) at once without causing PHP to throw a fatal error. This is one of the reasons that the Nibble PHP Framework requires a version of PHP which is at least 5.3.
Actionsbase: The actions classes must be called Actions and must extend Actionsbase so that the framework can load them:

Once all of above conditions are met, methods can be added to the Actions class. Each method corresponds to a URL. The rooting in Nibble PHP Framework is simple, if a method exists in the loaded Actions class, the system run it. Thus if the frontend application is running, meaning the actions.frontend.class.php is loaded, and the url is “”, the system will search for a method view and pass it the values “1″ and “nibble” if it exists. In order to make use of the variables passed from the URL, the simplest method is to create each method with one argument:

The default method to run is index and thus all actions classes should have a method called index. The rest of the methods are completely down to the URL’s and so can have any name. An example simple actions class should look something like:

Luke Rotherfield

Freelance PHP Developer
is a PHP developer dedicated to writing the most awesome liraries for his fellow devs :) enjoy

Latest posts by Luke Rotherfield (see all)

Leave a Comment