The best IT partner for your business English version

Quick start

Home Features Cases Downloads Apps Docs

More productivity with Adianti Studio Pro

  • Forms designer;
  • Automatic form generation;
  • Automatic datagrid generation;
  • Create DB from your UML;
Ver detalhes...

This quickstart guide provides the minimum steps required to create a very simple Adianti Framework application. Installation
The installation itself is quite simple. First, you get the framework here;

After, you have to create a directory under your httpdocs apache folder ("samples" for example) and just unzip the framework under this folder, making it available;
In the next step, we must verify if Apache has enabled the .htaccess files, once the framework uses these files to protect the access to some folders with configuration files, like app/config. The following lines must be present in httpd.conf or in some VirtualHost to enable this feature.
AllowOverride All
Besides this, you should also enable the display of errors of PHP in php.ini during the system's development. When the system go into production, remember to disable this directive, and turn on the error log.
display_errors = On

The installation is finished. Now we are going to setup the application.
For a deeper understanding about the framework directory structure, click here.
Database setup
Now the the framework is installed, we can setup the database structure. First, we are going to create a pretty simple sqlite database. This database will be located inside the app/database directory.
sqlite3 samples.db
sqlite> CREATE TABLE person (id serial, name text, address text, birthdate date, gender text);
Now, we have to configure the database access. Each database used by the application is configured by an INI file located in the app/config directory. This file will be named samples.ini. For another databases like Postgresql or Mysql, we have to fill all the parameters.
host = ""
name = "app/database/library.db"
port = ""
user = ""
pass = ""
type = "sqlite"
Creating Model classes
Now is time to create the application model. The model is derived from the framework class TRecord. This class provides methods like store(), delete() and load() that handle an object in the database. The use of these methods is explained in the tutorial. The next file is located in the folder app/model and is named Person.class.php.
  1. <?php
  2. class Person extends TRecord
  3. {
  4.     const TABLENAME 'person';
  5.     const PRIMARYKEY'id';
  6.     const IDPOLICY =  'max'// {max, serial} 
  8.     /**
  9.      * Constructor method
  10.      * @param $id Primary key to be loaded (optional)
  11.      */
  12.     public function __construct($id NULL)
  13.     {
  14.         parent::__construct($id);
  15.         parent::addAttribute('name');
  16.         parent::addAttribute('address');
  17.         parent::addAttribute('birthdate');
  18.         parent::addAttribute('gender');
  19.     }
  20. }
  21. ?>

The TABLENAME constant defines the name of the table the model class will handle and the PRIMARYKEY constant defines the primary key field. The framework do not handle composed keys. The IDPOLICY defines the strategy for new ID generation: max+1 or serial (leaves the primary key field empty and the database decides its new value).

The addAttribute() method limits the attributes that will be persisted (stored) in the database. Any attribute out of addAttribute() will be ignored by the persistence mechanism. When addAttribute() is not called, all the attributes will be persisted.
Creating Page controllers
Now its time to create the application controller. The simplest way to write an application controller is using standard controllers available in the framework. The TStandardForm provides a default aproach for form handling, while TStandardList provides a default aproach for datagrid handling.

The application controller is saved in the app/control directory. In this case, the class PersonForm is saved in the app/control/PersonForm.class.php file. All the application controller has a constructor method. In the constructor method we define the application visual structure. The TStandardForm standard controller provides methods like setDatabase() and setActiveRecord() to define the database name (see INI files) and the Active Record class that will deal the form data. The use of standard controller is explained in the tutorial

The next step is to create the application form. There are many ways to do that. Usually we will use the TForm class along with TTable or TPanel class. But if we need a fast form, we can use TQuickForm class. This container organizes the form fields in a standard layout. The addField() method is used to add fields in the form. Each field can use a different component from toolkit (TEntry, TDate, TCombo, and so on). We can see the available widgets in the tutorial The save button in the form calls the onSave() standard method provided by the TStandardForm class.
  1. <?php
  2. class PersonForm extends TStandardForm
  3. {
  4.     protected $form// form
  6.     function __construct()
  7.     {
  8.         parent::__construct();
  10.         parent::setDatabase('samples');
  11.         parent::setActiveRecord('Person');
  13.         $this->form = new TQuickForm('form_person');
  14.         $id        = new TEntry('id');
  15.         $name      = new TEntry('name');
  16.         $address   = new TEntry('address');
  17.         $birthdate = new TDate('birthdate');
  18.         $gender    = new TCombo('gender');
  19.         $options = array('M'=>'Male','F'=>'Female');
  20.         $gender->addItems($options);
  21.         $this->form->addQuickField('id',        $id,        100);
  22.         $this->form->addQuickField('name',      $name,      200);
  23.         $this->form->addQuickField('address',   $address,   200);
  24.         $this->form->addQuickField('birthdate'$birthdate100);
  25.         $this->form->addQuickField('gender',    $gender,    200);
  26.         $this->form->addQuickAction('Save',
  27.                new TAction(array($this'onSave')), 'ico_save.png');
  28.         parent::add($this->form);
  29.     }
  30. }
  31. ?>
Defining the application menu
Now, its time to define the application menu. The application menu is defined in the file menu.xml and is used by the standard frontends provided by the framework. That means its just a recommendation, because you can define another frontends using HTML/CSS. The application reads the menu.xml and presents the menu for the user.
  1. <menu>
  2. <menuitem label='Register'>
  3. <menu>
  4. <menuitem label='Person'>
  5. <menu>
  6. <menuitem label='Form'>
  7. <icon>app/images/ico_store.png</icon>
  8. <action>PersonForm</action>
  9. </menuitem>
  10. </menu>
  11. </menuitem>
  12. </menu>
  13. </menuitem>
  14. </menu>
Running the application
Now its time to test the application. To do that, we open the web browser and access the application folder under apache httdocs. This will make the apache load index.php frontend:
Access control system
Now that you have created a simple example and managed to run it, you probably will want to implement more controls, such as login form, and permissions for users or groups, so that only certain users can access some content. You do not need to implement these controls because they are already implemented, through the templates Template ERP, that incorporates the framework itself, and adds to it a layer that provides a permission control access by users and groups.   
Adianti Template ERP
Another samples
To learn more about the Adianti Framework, we made available different sample applications.
Click at this link and check at the left menu.