Core Concepts

PHPControls and PHPControls is built by following the core concepts. Understanding the concepts is very important especially if you plan to write and distribute your own add-ons.

App

In any PHPControls application you would always need to have an App class. Even if you do not create this class explicitly, Controls generally, will do it for you, however the common pattern is:

$app = new \phpctrl\ui\App('My App');
$app->initLayout('Centered');
$app->layout->add('LoremIpsum');

Seed

PHPControls is developed to be easy to read and with simple and concise syntax. We make use of dynamic nature of PHP, therefore two syntax patterns are supported everywhere:

$app->layout->add(new \phpctrl\ui\Button('Hello'));

and

$app->layout->add(['Button', 'Hello']);

Method add() supports arguments in a various formats and we call that “Seed”. The same format can be used elsewhere, for example:

$button->icon = 'book';

We call this format ‘Seed’. This section will explain how and where it is used.

Render Tree

PHPControls is allows you to create Controls hierarchically. Once complete, the component hierarchy will render itself and will present HTML output that would appear to user.

You can create and link multiple UI objects together before linking them with other chunks of your UI:

$msg = new \phpctrl\ui\Message('Hey There');
$msg->add(new \phpctrl\ui\Button('Button'));

$app->layout->add($msg);

To find out more about how Controls are linked up together and rendered, see:

Agile Data

PHPControls framework is focused on building User Interfaces, but quite often interface must present data values to the user or even receive data values from user’s input.

PHPControls uses various techniques to present data formats, so that as a developer you wouldn’t have to worry over the details:

$user = new User($db);
$user->load(1);

$view = $app->layout-add(['template'=>'Hello, {$name}, your balance is {$balance}']);
$view->setModel($user);

Next section will explain you how the PHPControls interacts with the data layer and how it outputs or inputs user data.

Callbacks and Virtual Pages

By relying on the ability of generating Unique Name, it’s possible to create several classes for implementing PHP call-backs. They follow the pattern:

  • present something on the page (maybe)
  • generate URL with unique parameter
  • if unique parameter is passed back, behave differently

Once the concept is established, it can even be used on a higher level, for example:

$button->on('click', function() { return 'clicked button'; });