Configs

Contents...

All application-related configuration files reside in lib/config/ subdirectory inside the application directory. Changing the location or the name of a configuration file is not allowed.

File app.php

File app.php is the main configuration file of an application. It contains the application name, the path to the application icon file, the current version number, the database tables name prefix, availability of an application interface optimized for mobile devices, availability of the frontend interface, and other parameters.

Example of the app.php file for Contacts application:

<?php

return array(
    'name' => 'Contacts',
    'img' => 'img/contacts.png',
    'rights' => true,
    'version' => '0.0.1',
    'system' => true,
);

Below is the list of all parameters which can be used in file app.php:

File db.php

File db.php contains the application database tables description in the following form:

array(
     'table1' => array(
         'field1' => array(FIELD_TYPE,  PARAMETERS),
         'field2' => array(FIELD_TYPE,  PARAMETERS),
         ...
     ),
     'table2' => array( 
         ...
     )
);

Field types are standard for MySQL: int, varchar, text, datetime, etc.

Example (application Guestbook 2):

<?php

return array(
    'guestbook2' => array(
        'id' => array('int', 11, 'null' => 0, 'autoincrement' => 1),
        'contact_id' => array('int', 11, 'null' => 0, 'default' => '0'),
        'name' => array('varchar', 255, 'null' => 0, 'default' => ''),
        'text' => array('text', 'null' => 0),
        'datetime' => array('datetime', 'null' => 0),
        ':keys' => array(
            'PRIMARY' => 'id',
            'datetime' => 'datetime',
        ),
    ),
);

You can generate file db.php for any application by executing the following command:

php wa.php generateDb APP_ID

In this case all tables with names containing APP_ID or APP_ID_% will be found (be careful if you have some plugins installed, because the descriptions of their tables will also be added to the application's db.php file).

Update db.php
php wa.php generateDb APP_ID --update
This command will simply update the descriptions of tablew, which are already contained in file db.php

Explicitely specify the table names of an application:
php wa.php generateDb APP_ID table1 table2 table3
This command will write only the descriptions of the specified tables to file db.php.

The same applies for plugins with the exception that you have to specify APP_ID/PLUGIN_ID. Example:
php wa.php generateDb blog/tag blog_tag blog_post_tag
blog is an APP_ID, tag is a PLUGIN_ID; blog_tag and blog_post_tag are the plugin's table names.

File routing.php

File routing.php contains HTTP request routing rules for the application frontend.

Example of file routing.php for Blog application:

<?php

return array(
    'post/[i:id]/?' => 'frontend/post',
    'comment/add/[i:id]' => 'frontend/addComment'
    'rss/?' => 'frontend/rss',
    '' => 'frontend',
    '[s:url]/?' => 'frontend/post'
);

Read more about frontend request routing.

File logs.php

File logs.php contains the list of user-triggered application actions, which must be saved in the system log.

Example of file logs.php for Stickies application:

<?php

return array(
    'board_add' => array(),
    'board_edit' => array(),
    'board_delete' => array(),
    'sticky_add' => array(),
    'sticky_edit' => array(),
    'sticky_move_to_board' => array(),
    'sticky_delete' => array(),
);

Read more about logging user actions in section "User actions logging".

File factories.php

This file is useful for overriding some system parameters; e.g., to use an alternative template engine instead of the default Smarty or to use app’s own backend requests dispatcher.

The file must contain an associative PHP array. Array keys must be the names of the parameters which you need to override, and their new values must be the array items’ values.

If a value is a string then it must be the name of a custom class which must be used instead of the framework’s default class. If a value is a simple array then its first item must be the class name, and the second parameter must be its constructor parameters.

What system parameters you can override:

Example

Overriding default Smarty parameters: use double curly brackets instead of single brackets in HTML templates.

<?php
  
return array(
    'view' => array(
        'waSmarty3View',
        array(
            'left_delimiter'  => '{{',
            'right_delimiter' => '}}',
        )
    ),
);

Detailed access rights configuration file

Detailed access rights are described in a PHP class extending abstract system class waRightConfig. The PHP file of the access rights settings class must be named according to rule {APP_ID}RightsConfig.class.php. For example, access rights configuration file for an application with APP_ID guestbook must be named guestbookRightConfig.class.php:

<?php

class guestbookRightConfig extends waRightConfig
{

    public function init()
    {
        $this->addItem('delete', 'Can delete posts', 'checkbox');
    }

}

Custom configuration files

In addition to the standard configuration files, your application can use its own files to store various useful parameters.

The default method of storing configuration data in Webasyst applications is a PHP file returning an array of data. This format is handy for easily retrieving configuration data and using them in your app's source code. Note that all configuration should reside in directory wa-apps/APP_ID/lib/config/.

PHP arrays are not the only acceptable format for storing data in a configuration file. Each developer is free to define his own format and the appropriate data reading routine. For example, a configuration file may contain a class or the result of the serialize() function.

Suppose that your application (which will be used for processing customer requests) requires some initial data for normal functioning; e.g. a basic list of request statuses (which you may want to make editable). These statuses will be available right after the installation, which will make the application ready for use without prior setup.

Below is an example of simple configuration file statuses.php with a status list:

<?php

return array(
    'new',
    'discussion',
    'closed',
    'reopened',
    'canceled',
    'deleted',
);

To make this status list accessible in your application, you need to read the contents of the configuration file and assign it to a variable. Framework's system class waAppConfig provides a useful method returning the absolute path to an application configuration file by its name: getAppConfigPath(). To use this method, first obtain access to an instance of class waAppConfig as shown below:

wa()->getConfig()->getAppConfigPath($config)

Method getAppConfigPath() accepts a string parameter containing the name of the configuration file without extension .php. For example, to obtain the absolute path to file wa-apps/APP_ID/lib/config/statuses.php, use the following code:

wa()->getConfig()->getAppConfigPath('statuses')

Once you have the path to the file, assign the file's contents to a variable; e.g.:

$statuses = include wa()->getConfig()->getAppConfigPath('statuses');

User-defined configuration

The above-described method of storing configuration data allows specifying some static parameters, which cannot be modified by users because such configuration files will be overwritten during installation of updates. To preserve custom parameters, you may use configuration files which are not affected by software updates. Such files should be saved in wa-config/apps/APP_ID/ directory. To obtain the path to some file in that directory, use method getConfigPath() of system class waSystemConfige.g.:

$config_file_path = wa()->getConfig()->getConfigPath('userconfig.php', true, 'myapp');

This example will return the path to file wa-config/apps/myapp/userconfig.php.