Fork me on GitHub

Nibble Development

Nibble Development

PHP classes and libraries for developers

The model: RedBeanPHP

The Nibble PHP Framework uses RedBeanPHP ORM. RedBeanPHP’s unique method of on the fly table modifications through Beans lends itself perfectly to the plug-in structure of the Nibble PHP Framework. RedBeanPHP allows a row from a table to be called and instantiated as an object. If the developer then adds a variable (which represent the table columns) to the object that does not yet exist, RedBeanPHP adds the variable as a new column with a type based on the value assigned to the variable.

RedBeanPHP has a very comprehensive set of Documentation that explains how to use the classes. Nibble PHP Framework does not add any functionality to RedBeanPHP so all of the methods described in the documentation can be used with no modification to the way they are called. An example, from the blog Bite actions class, of using RedBeanPHP in the Nibble PHP Framework:

In the example above, a user Bean is loaded, a blog Bean is then dispensed and populated, and, finally the blog Bean is linked to the user Bean (the blog gets the user id added to it as a foreign key) and saved. As seen above it is a very simple process to add rows to tables and update or add columns.

Database schema file, schema.php

Each Bite requires a schema file named schema.php. This file sits in the Bite directory just like the config.php file. Schema.php is run the first time the Bite is activated and should build any tables that the Bite requires. The simplest way to do this is dispensing a new Bean for each table, populating and linking the beans as necessary and then saving them. Here is an example of a schema file from the demo Bite blog:

As the example shows, the entire table structure for the blog Bite is set up using 4 Beans in a simple and easy to understand manner and without huge SQL statements.

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