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:

PHP

1

2

3

4

5

6

7

8

9

10

11

<?php

/*

* Define application

*/

define('APP','admin');

includedirname(dirname(__FILE__)).'/lib/config/config.php';

if(DBUSER=='')

requireROOT.'/lib/config/setup.php';

else

newInitialise();

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:

PHP

1

namespaceuser\admin;

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:

PHP

1

classActions extends\ActionBase

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 “sitename.com/view/1/nibble”, 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:

PHP

1

publicfunctionindex($var_array=array()){}

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:

Some of our projects

Hosting

We host with DreamHost, they have been fantastic value for money. They give us almost 100% uptime and have a great support team. Plus, use the code NIBBLE2011 to get $30 off your setup fee, just enter it into the promotional code field when you sign up.

We Recommend

Symfony2: Symfony2 is our favourite framework, it is fast, powerful, fast to learn, and, even faster to develop large web applications in.

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 cu