Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Basic concepts

fballiano edited this page Aug 30, 2012 · 1 revision

Structure of a P4A application, the index.php file and the "objects" folder

Every P4A application has the same basic structure:

  • an index.php file: representing the only entry point for every call to the application, its task is to "boot" the application and configure it (commonly setting a few constants such as the path to the uploads directory)
  • an objects folder: will contain all the classes of the application logic, remember (by default) all PHP files within the objects folder will be automatically included

Let's take a look at a minimal index.php file

// requiring p4a
require '../p4a/p4a.php';
 
// telling p4a to gather the 'my_application' application
$my_application = P4A::singleton('my_application');
 
// start the application
$my_application->main();

In the sample code above we created an instance of an object called my_application. Due to this fact we can imagine that we have to create a my_application PHP class file within the objects folder. This class must extend the P4A class.

Extending the P4A class

The class extending P4A, in our sample named my_application, it's the "application" class, something like the coordinator of everything the application will do, a global object that will store all the application objects inside itself. This object should do at least one thing: open a mask.

class my_application extends P4A
{
	public function __construct()
	{
		// we've to call the original p4a constructor
		parent::__construct();

		// let's open the "my_mask" mask
		$this->openMask('my_mask');
	}
}

What is a mask?

Masks could be defined as the screens of our application, but a mask is much more, it's a hybrid container which:

  • displays GUI elements (widgets) on your page
  • interacts with data (DB or other data sources) with ease
  • handles user fired events (clicks on buttons or whatever event the coder decide to manage)

All these concepts will become clear as you continue reading the manual and start trying to create an application, for now just think of the mask as your page. In the previous code we told P4A to open the my_mask mask, thus we have to create a my_mask PHP class within the objects folder. This class will extend the P4A_Mask class.

class my_mask extends P4A_Mask
{
	public function __construct()
	{
		// never forget to call the original P4A_Mask's constructor
		parent::__construct(); 
	}
}