First Application

Where everything begins

Nice, now we are talking let’s do it:

Once we had everything ( just a git clone and a little php.ini configuration ) downloaded and installed let’s BURN the room:

Install using Generator Tool

The first thing you have to do is go to your PhpBURN folder and, using prompt you will:

Generating Files

$ php app/generator/generate.php

That will generate something like that

Wellcome to PhpBURN structure generator
This tool will help you to generate the basics structure to create a PhpBURN based system

Please type the path to your system
(if it does not exists will be created and all files and subfolders will be deleted - BE CAREFUL):

Then you will type your new site’s destiny folder, in our example it will be /var/www/html/mySite
PLEASE BE CAREFUL because this cleans everything in the destiny folder and you will NEVER get that back

Checking Files

Ok, so now we will have a structure like this:

PhpBURN Structure
PhpBURN Structure

Alright, everything is perfect, so now let’s start configuring our application.

Open your favorite PHP Editor ( Netbeans, Eclipse PDT, TextMate, VI, VIM, NOTEPAD, PHP EDITOR, etc… ) and let’s start.

PhpBURN Structure
PhpBURN Structure

Creating the Database

In this Example we are going to use MySQL but you can choose and use MySQL, Postgree, MSSQL and in a near future Oracle, MongoDB, CouchDB and SQLITE and more…

So we have created in our localhost MySQL database a database called example and that we are going to use during all this documentation.

Empty Example Database
Empty Example Database

Ok, so now we have a complete site structure ( /var/www/html/mySite/ ), a database ( example )and a database user/password ( example/phpburn ) let’s start using it.

Configuring the System

Lets understand a little about the file structure:

– .htaccess ( apache configuration for clean urls )
– config.php ( main config file for the site )
– index.php ( index – usualy we don’t touch this file )
– sysConfig.php ( system configuration – usualy we don’t touch this file )
– system/
— config/ ( configs folder, here you can configure and customize each module that you are using )
— controller.php
— model.php
— routes.php ( configure the url routes using regex )
— view.php
— controllers/ ( where controllers will be stored )
— model/ ( where models will be stored )
— views/ ( where views will be stored )
— _errorPages/ ( error pages for controller method $this->callErrorPage(‘name’);

Understanding the configuration files:

Ok did this let’s open the config.php file, here we will find a structure similar to this:

/**
 * This file has been designed to auto-config all your
 * path variables like path, url and others automaticaly
 * for this it have to stay the same folder as your index.php
 * 
 * If you want to put it in another place you should to config manualy
 * or modify our auto-generate code.
 * 
 * @author Kléderson Bueno 
 * @version 1.0
 */
@ob_start();
@session_start();

################################
# System Settings
################################
require_once('sysConfig.php');


################################
# Error and Message System
################################
error_reporting(E_ALL & ~E_NOTICE);

//Turn the Messages and Logs and Erros ON
PhpBURN_Message::setMode(PhpBURN_Message::FIREBUG); //You can Choose FIREPHP, BROWSER OR FILE for now than more can came latter


################################
# Internacionalization Settings
################################
setlocale(LC_ALL, 'en_US');
date_default_timezone_set('America/Sao_Paulo');


################################
# Modules
################################
# To load the module just remove the # comment from the line

# Views
#PhpBURN::loadModule('View');

# Controller
#PhpBURN::loadModule('Controller');

# To load the module just remove the # comment from the line
#PhpBURN::loadModule('Model');

NOTE: Here we will explain only how to config the basics, in Tutorial session you can find a more elaborated and detailed information about each file and each config.

Now i will UNCOMMENT all the avaliable modules so i can work with the complete framework. Of cource you can use only what you want/need but here we will explain them all.

################################
# Modules
################################
# To load the module just remove the # comment from the line

# Views
PhpBURN::loadModule('View');

# Controller
PhpBURN::loadModule('Controller');

# To load the module just remove the # comment from the line
PhpBURN::loadModule('Model');

And “voilà” now our framework is ready, you can point your browser to http://localhost/mySite and see the magic happening ( now we have our system up and running with all features isn’t that cool? And the coolest is we took no more than 50 seconds )

For last we will configure our system/config/model.php to connect in our database.

Your file should looks like that:


################################
# Model Settings
################################
$thisConfig = array(
		/**
		 * Database configuration ( Default )
		 * 
		 * This configuration will be used by defaul when
		 * package configs are not setted up
		 */
		'dialect' => 'MySQL', // our dialect in this case MySQL
		'database' => 'example', // database name
		'user' => 'example', // database user
		'password' => 'phpburn', // database password
		'port' => '3306', // database port
		'host' => 'localhost', // database host

		/**
		 * Structure configuration
		 */
		'class_path' => SYS_MODEL_PATH,

		/**
		 * database-options changes according to the database used
		 * So if you want to know what options have each database please
		 * look at documentation in section Dialects
		 * 
		 * OPTIONAL
		 */
		'database_options' => array(),

		/**
		 * options are general configs for the project
		 * See Configuration section at documentation for more information
		 * 
		 * OPTIONAL
		 */
		'options' => array(),
			
			'packages' => array(
				'phpburn' // our main package
			)
);

//Loading the configuration file
$config = new PhpBURN_Configuration($thisConfig);

$configItems = $config->getConfig();

foreach($configItems as $package => $infos) {
    $path = $infos->class_path . $package . DS;
    set_include_path(get_include_path() . ': '.$path);
}

spl_autoload_register(null, false);
spl_autoload_extensions(SYS_MODEL_EXT);
spl_autoload_register('PhpBURN::import');

It’s done, now you can go to controllers and create more controllers, models and create more models, views and create more views… see Tutorial section on PhpBURN’s site and Enjoy this Brave New World.