K4:Constants
From In-Portal Developers Guide
Current revision (18:26, 26 November 2010) (view source) (Languages sidebox) |
|||
(7 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
{{toc | category = Структура приложения | sortkey = 003.001}} | {{toc | category = Структура приложения | sortkey = 003.001}} | ||
- | + | In K4, constants are separated based on their meaning into: | |
- | In K4, constants are separated based on their meaning | + | |
* '''system''' - defined in "<code>core/kernel/startup.php</code>" | * '''system''' - defined in "<code>core/kernel/startup.php</code>" | ||
* '''general application''' - defined in "<code>core/kernel/constants.php</code>" | * '''general application''' - defined in "<code>core/kernel/constants.php</code>" | ||
Line 21: | Line 20: | ||
This constant is used only to correctly determine the value of the constant [[#BASE_PATH|BASE_PATH]]. If this constant isn't defined in time, then links built with the help of the method "<code>kApplicaton::HREF</code>" will be incorrect. | This constant is used only to correctly determine the value of the constant [[#BASE_PATH|BASE_PATH]]. If this constant isn't defined in time, then links built with the help of the method "<code>kApplicaton::HREF</code>" will be incorrect. | ||
|- | |- | ||
- | | {{ConfigProperty|SERVER_NAME}} || | + | | {{ConfigProperty|SERVER_NAME}} || Имя виртуального хоста (<code>VirtualHost</code>), под которым запущен данный сайт (содержание переменной [http://lv.php.net/reserved.variables <nowiki>$_SERVER['SERVER_NAME']</nowiki>]). В случае, если название виртуального хоста получить не удалось, то будет использован хост, указанный в константе [[#DOMAIN|DOMAIN]] (из файла "<code>config.php</code>"). Функциональность работающая в случае, когда не удалось получить имя виртуального хоста доступна начиная с [[K4:Core v 4.3.9|Core v 4.3.9]]. |
|- | |- | ||
| {{ConfigProperty|WRITEABLE}} || The contents of the variables [[#FULL_PATH|FULL_PATH]] and [[#WRITEABLE_BASE|WRITEABLE_BASE]] together. | | {{ConfigProperty|WRITEABLE}} || The contents of the variables [[#FULL_PATH|FULL_PATH]] and [[#WRITEABLE_BASE|WRITEABLE_BASE]] together. | ||
Line 62: | Line 61: | ||
! name || description | ! name || description | ||
|- | |- | ||
- | | {{ConfigProperty|erSUCCESS}} || Event finished working successfully | + | | {{ConfigProperty|erSUCCESS}} || Event finished working successfully. Once the event finishes, there is an automatic redirect so that the event isn't called again in case the user refreshes the page (F5). |
|- | |- | ||
| {{ConfigProperty|erFAIL}} || Event finished working, but didn't accomplish one or more of the requested tasks. There won't be a redirect. | | {{ConfigProperty|erFAIL}} || Event finished working, but didn't accomplish one or more of the requested tasks. There won't be a redirect. | ||
|- | |- | ||
- | | {{ConfigProperty|erFATAL}} || The event didn't accomplish any part of its task ([[K4:Hooks| | + | | {{ConfigProperty|erFATAL}} || The event didn't accomplish any part of its task ([[K4:Hooks|hooks]] won't continue). There won't be a redirect. |
|- | |- | ||
- | | {{ConfigProperty|erPERM_FAIL}} || Checking [[К4:Permissions| | + | | {{ConfigProperty|erPERM_FAIL}} || Checking [[К4:Permissions|access permissions]] wasn't successful. There will be an automatic redirect to a template letting the user know that he doesn't have the required permissions for the event. |
|- | |- | ||
| {{ConfigProperty|erSTOP}} || The event returns a response to an [[K4:Ajax|AJAX]] request. The template won't be parsed after running the event, debugger code won't be added either. | | {{ConfigProperty|erSTOP}} || The event returns a response to an [[K4:Ajax|AJAX]] request. The template won't be parsed after running the event, debugger code won't be added either. | ||
Line 82: | Line 81: | ||
|- | |- | ||
| {{ConfigProperty|EDITING_MODE_LAYOUT}} | | {{ConfigProperty|EDITING_MODE_LAYOUT}} | ||
- | | Site editing mode where only the content of blocks can be changed that were setup using the "<code> layout_view </ code>" option: | + | | Site editing mode where only the content of blocks can be changed that were setup using the "<code> layout_view </code>" option: |
<source lang="xml"> | <source lang="xml"> | ||
<inp2:m_RenderElement name="block_name" layout_view="1"/> | <inp2:m_RenderElement name="block_name" layout_view="1"/> | ||
Line 97: | Line 96: | ||
|} | |} | ||
- | * | + | * miscellaneous: |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! name || description || value |
|- | |- | ||
- | | {{ConfigProperty|ENV_VAR_NAME}} || | + | | {{ConfigProperty|ENV_VAR_NAME}} || The value of this constant is used to determine the name of the [[K4:Переменная окружения|environment variable]] in a request to the server. || <center><code>env</code></center> |
|- | |- | ||
- | | {{ConfigProperty|VALUE_LIST_SEPARATOR}} || | + | | {{ConfigProperty|VALUE_LIST_SEPARATOR}} || The value that will be used for associating [[K4:Formatters#options|possible options]] in the <code>ValueList</code> fields (in all tables except the [[K4:ConfigurationAdmin|ConfigurationAdmin]] table). || <center><code><nowiki>||</nowiki></code></center> |
|- | |- | ||
| {{ConfigProperty|REGEX_EMAIL_USER}} | | {{ConfigProperty|REGEX_EMAIL_USER}} | ||
- | | | + | | Regular expression that checks the name part of an <code>email</code>. Using constants [[#REGEX_EMAIL_USER|REGEX_EMAIL_USER]] and [[#REGEX_EMAIL_DOMAIN|REGEX_EMAIL_DOMAIN]] it's possible to put together a regular expression that checks the email address: |
<source lang="php"> | <source lang="php"> | ||
$regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; | $regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; | ||
</source> | </source> | ||
- | + | Constant available since [[K4:Core v 4.0.1|Core v 4.0.1]]. | |
| <pre>[-a-zA-Z0-9!\#$%&*+\/=?^_`{|}~.]+</pre> | | <pre>[-a-zA-Z0-9!\#$%&*+\/=?^_`{|}~.]+</pre> | ||
|- | |- | ||
| {{ConfigProperty|REGEX_EMAIL_DOMAIN}} | | {{ConfigProperty|REGEX_EMAIL_DOMAIN}} | ||
- | | | + | | Regular expression that checks the <code>domain</code> in an <code>email</code> address. Using constants [[#REGEX_EMAIL_USER|REGEX_EMAIL_USER]] and [[#REGEX_EMAIL_DOMAIN|REGEX_EMAIL_DOMAIN]] it's possible to put together a regular expression that checks the email address: |
<source lang="php"> | <source lang="php"> | ||
$regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; | $regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; | ||
</source> | </source> | ||
- | + | Constant available since [[K4:Core v 4.0.1|Core v 4.0.1]]. | |
| <pre>[a-zA-Z0-9]{1}[-.a-zA-Z0-9_]*\.[a-zA-Z]{2,6}</pre> | | <pre>[a-zA-Z0-9]{1}[-.a-zA-Z0-9_]*\.[a-zA-Z]{2,6}</pre> | ||
+ | |- | ||
+ | | {{ConfigProperty|ALLOW_DEFAULT_SETTINGS}} | ||
+ | | Данная константа задумана для передачи в метод "<code>kApplication::RecallPersistentVar</code>" в качестве значения по умолчанию. Это подробнее показано на приведённом ниже примере. | ||
+ | <source lang="php"> | ||
+ | $value = $this->Application->RecallPersistentVar('VarName', ALLOW_DEFAULT_SETTINGS); | ||
+ | </source> | ||
+ | Если требуемой переменной в таблице [[K4:PersistentSessionData|PersistentSessionData]] нету и используется эта константа, то будет возвращено значение этой переменной взятое у пользователя, указанного в конфигурационной переменной [[K4:Configuration#DefaultSettingsUserId|DefaultSettingsUserId]]. Данная константа доступна начиная с [[K4:Core v 4.2.2|Core v 4.2.2]]. | ||
+ | | <center><code>_USE_DEFAULT_USER_DATA_</code></center> | ||
|} | |} | ||
- | + | Constants are identifier values that can't change as the script runs. | |
- | == | + | == config.php constants == |
- | + | In the root directory of the project (the one that's in the [[#FULL_PATH|FULL_PATH]] constant) there is a file <code>config.php</code> that contains settings for connecting to the database along with other parameters that by initializing K4 become constants. Into this file, a '''commit can never be made'''. By its format, this file looks similar to a regular ini file. The only difference is the file extension and the protected php design in the beginning of the file. | |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! constant name || option name || description |
|- | |- | ||
- | | {{ConfigProperty|SQL_TYPE}} || <code>DBType</code> || | + | | {{ConfigProperty|SQL_TYPE}} || <code>DBType</code> || Database server type. Right now, only MySQL is supported. |
|- | |- | ||
- | | {{ConfigProperty|SQL_SERVER}} || <code>DBHost</code> || IP | + | | {{ConfigProperty|SQL_SERVER}} || <code>DBHost</code> || IP address or server name of the database. |
|- | |- | ||
- | | {{ConfigProperty|SQL_USER}} || <code>DBUser</code> || | + | | {{ConfigProperty|SQL_USER}} || <code>DBUser</code> || Username for connecting to the database. |
|- | |- | ||
- | | {{ConfigProperty|SQL_PASS}} || <code>DBUserPassword</code> || | + | | {{ConfigProperty|SQL_PASS}} || <code>DBUserPassword</code> || Password for connecting to the database. |
|- | |- | ||
- | | {{ConfigProperty|SQL_DB}} || <code>DBName</code> || | + | | {{ConfigProperty|SQL_DB}} || <code>DBName</code> || Database name. |
|- | |- | ||
- | | {{ConfigProperty|SQL_COLLATION}} || <code>DBCollation</code> || | + | | {{ConfigProperty|SQL_COLLATION}} || <code>DBCollation</code> || Collation type used when working with the database (for example "<code>utf8_general_ci</code>"). |
|- | |- | ||
- | | {{ConfigProperty|SQL_CHARSET}} || <code>DBCharset</code> || | + | | {{ConfigProperty|SQL_CHARSET}} || <code>DBCharset</code> || Data encoding type used for working with the database (for example "<code>utf8</code>"). |
|- | |- | ||
- | | {{ConfigProperty|TABLE_PREFIX}} || <code>TablePrefix</code> || | + | | {{ConfigProperty|TABLE_PREFIX}} || <code>TablePrefix</code> || Prefix of database tables of the project in the database. |
|- | |- | ||
- | | {{ConfigProperty|DOMAIN}} || <code>Domain</code> || | + | | {{ConfigProperty|DOMAIN}} || <code>Domain</code> || Domain where the site is located. Used for leaving SSL-mode and for checking an <code>In-Portal</code> license. |
|- | |- | ||
- | | {{ConfigProperty|ADMIN_DIRECTORY}} || <code>AdminDirectory</code> || | + | | {{ConfigProperty|ADMIN_DIRECTORY}} || <code>AdminDirectory</code> || Location of the administrative console directory relative to [[#FULL_PATH|FULL_PATH]]. Available starting with [[K4:Core v 4.3.0|Core v 4.3.0]]. |
|- | |- | ||
- | | {{ConfigProperty|EDITOR_PATH}} || <code>EditorPath</code> || | + | | {{ConfigProperty|EDITOR_PATH}} || <code>EditorPath</code> || Location of the directory with the <code>FCKEditor</code>, relative to [[#FULL_PATH|FULL_PATH]] (usually "<code>/core/editor/</code>"). Available starting with [[K4:Core v 4.3.2|Core v 4.3.2]]. |
|- | |- | ||
- | | {{ConfigProperty|WRITEABLE_BASE}} || <code>WriteablePath</code> || | + | | {{ConfigProperty|WRITEABLE_BASE}} || <code>WriteablePath</code> || Directory into which the server has permissions to write (usually "<code>/system</code>"). |
|- | |- | ||
- | | {{ConfigProperty|APPLICATION_CLASS}} || <code>ApplicationClass</code> || | + | | {{ConfigProperty|APPLICATION_CLASS}} || <code>ApplicationClass</code> || Class that's used to create an [[K4:Application|Application]] object, for example "<code>EApplication</code>". |
|- | |- | ||
- | | {{ConfigProperty|APPLICATION_PATH}} || <code>ApplicationPath</code> || | + | | {{ConfigProperty|APPLICATION_PATH}} || <code>ApplicationPath</code> || Location of the file with the class indicated in [[#APPLICATION_CLASS|APPLICATION_CLASS]], relative to the root of the site (with the "<code>/</code>" character in front), for example "<code>/custom/units/sections/e_application.php</code>". |
|} | |} | ||
+ | |||
+ | [[en:{{FULLPAGENAME}}]] | ||
+ | [[ru:K4:Константы]] |
Current revision
| ||
---|---|---|
Статьи в этой категории | ||
In K4, constants are separated based on their meaning into:
- system - defined in "
core/kernel/startup.php
" - general application - defined in "
core/kernel/constants.php
" - modular - defined in the not required file "
<module_name>/constants.php
"
System constants
name | description |
---|---|
FULL_PATH | Full path to the site in the file system of the server. |
BASE_PATH | Directory where the site is located (relative to $_SERVER['DOCUMENT_ROOT']) |
REL_PATH
| Path from the root of the project to the PHP-file (usually that's "index.php "), that the site user enters. Defining this constant must be done before or right after defining the constant FULL_PATH in this PHP file. This constant must be defined in all cases, when the PHP-file is not in the root of the project or in its "admin " directory. Examples:
file: testing/folder/index.php - constant: "testing/folder" file: sub_folder/index.php - constant "sub_folder" This constant is used only to correctly determine the value of the constant BASE_PATH. If this constant isn't defined in time, then links built with the help of the method " |
SERVER_NAME | Имя виртуального хоста (VirtualHost ), под которым запущен данный сайт (содержание переменной $_SERVER['SERVER_NAME']). В случае, если название виртуального хоста получить не удалось, то будет использован хост, указанный в константе DOMAIN (из файла "config.php "). Функциональность работающая в случае, когда не удалось получить имя виртуального хоста доступна начиная с Core v 4.3.9.
|
WRITEABLE | The contents of the variables FULL_PATH and WRITEABLE_BASE together. |
MAX_UPLOAD_SIZE | The maximum size of the file that can be uploaded to the server (in bytes). |
Исходный код требует реорганизации (refactoring ).Constants WRITEABLE and WRITEBALE_BASE are incorrectly named (misspelled). In English obviously, the correct names would be WRITABLE and WRITABLE_BASE respectively. |
Example:
http://alex.prod.intechnic.lv/test_project - path to the web browser FULL_PATH - "/home/sites/alex/web/test_project" BASE_PATH - "/test_project" SERVER_NAME - "alex.prod.intechnic.lv" WRITEBALE_BASE - "/system" WRITEBALE - "/home/sites/alex/web/test_project/system"
General application constants
- common types of records (statuses) in the database:
name | description | value |
---|---|---|
STATUS_ACTIVE | Active record. | |
STATUS_DISABLED | Inactive record. | |
STATUS_PENDING | Record is awaiting approval by the administrator. | |
- status of sections in the navigation tree in the administrative console:
name | description |
---|---|
stTREE | Section is present only in the navigation tree (almost all sections). |
stTAB | Section is present only as a tab (see In-Commerce:Discounts & Coupons). |
- status of finished events in K4:
name | description |
---|---|
erSUCCESS | Event finished working successfully. Once the event finishes, there is an automatic redirect so that the event isn't called again in case the user refreshes the page (F5). |
erFAIL | Event finished working, but didn't accomplish one or more of the requested tasks. There won't be a redirect. |
erFATAL | The event didn't accomplish any part of its task (hooks won't continue). There won't be a redirect. |
erPERM_FAIL | Checking access permissions wasn't successful. There will be an automatic redirect to a template letting the user know that he doesn't have the required permissions for the event. |
erSTOP | The event returns a response to an AJAX request. The template won't be parsed after running the event, debugger code won't be added either. |
- constants used when editing site content through the administrative console.
name | description |
---|---|
EDITING_MODE | This constant, starting from Core v 5.0.0, replaces the methods EditMode in the event handler and tags of the prefixes "st " and "cms ". The value of this constant may be the same as the value of the below 3 constant or equal to zero, which means that the user is currently not in the editing mode of the site. Regardless of the editing mode of the site, the orange "Edit " buttons will appear above the parts of the template that can be changed. This constant will be available starting with Core v 5.0.0.
|
EDITING_MODE_CMS | Site editing mode, where the only things that can be changed are items contained in cms-blocks (this was the only possible site editing mode until Core v 5.0.0). This constant will be available starting with Core v 5.0.0. |
EDITING_MODE_LAYOUT
| Site editing mode where only the content of blocks can be changed that were setup using the " layout_view " option:
<inp2:m_RenderElement name="block_name" layout_view="1"/> In the theme " |
EDITING_MODE_DESIGN
|
Site editing mode, where the design of the blocks can be changed, i.e. those blocks that were indicated in the parameter " <inp2:m_RenderElement name="element_name" design="design_block_name"/> In the theme " |
- miscellaneous:
name | description | value |
---|---|---|
ENV_VAR_NAME | The value of this constant is used to determine the name of the environment variable in a request to the server. | env |
VALUE_LIST_SEPARATOR | The value that will be used for associating possible options in the ValueList fields (in all tables except the ConfigurationAdmin table). | || |
REGEX_EMAIL_USER
| Regular expression that checks the name part of an email . Using constants REGEX_EMAIL_USER and REGEX_EMAIL_DOMAIN it's possible to put together a regular expression that checks the email address:
$regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; Constant available since Core v 4.0.1. | [-a-zA-Z0-9!\#$%&*+\/=?^_`{|}~.]+ |
REGEX_EMAIL_DOMAIN
| Regular expression that checks the domain in an email address. Using constants REGEX_EMAIL_USER and REGEX_EMAIL_DOMAIN it's possible to put together a regular expression that checks the email address:
$regexp = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; Constant available since Core v 4.0.1. | [a-zA-Z0-9]{1}[-.a-zA-Z0-9_]*\.[a-zA-Z]{2,6} |
ALLOW_DEFAULT_SETTINGS
| Данная константа задумана для передачи в метод "kApplication::RecallPersistentVar " в качестве значения по умолчанию. Это подробнее показано на приведённом ниже примере.
$value = $this->Application->RecallPersistentVar('VarName', ALLOW_DEFAULT_SETTINGS); Если требуемой переменной в таблице PersistentSessionData нету и используется эта константа, то будет возвращено значение этой переменной взятое у пользователя, указанного в конфигурационной переменной DefaultSettingsUserId. Данная константа доступна начиная с Core v 4.2.2. | _USE_DEFAULT_USER_DATA_ |
Constants are identifier values that can't change as the script runs.
config.php constants
In the root directory of the project (the one that's in the FULL_PATH constant) there is a file config.php
that contains settings for connecting to the database along with other parameters that by initializing K4 become constants. Into this file, a commit can never be made. By its format, this file looks similar to a regular ini file. The only difference is the file extension and the protected php design in the beginning of the file.
constant name | option name | description |
---|---|---|
SQL_TYPE | DBType | Database server type. Right now, only MySQL is supported. |
SQL_SERVER | DBHost | IP address or server name of the database. |
SQL_USER | DBUser | Username for connecting to the database. |
SQL_PASS | DBUserPassword | Password for connecting to the database. |
SQL_DB | DBName | Database name. |
SQL_COLLATION | DBCollation | Collation type used when working with the database (for example "utf8_general_ci ").
|
SQL_CHARSET | DBCharset | Data encoding type used for working with the database (for example "utf8 ").
|
TABLE_PREFIX | TablePrefix | Prefix of database tables of the project in the database. |
DOMAIN | Domain | Domain where the site is located. Used for leaving SSL-mode and for checking an In-Portal license.
|
ADMIN_DIRECTORY | AdminDirectory | Location of the administrative console directory relative to FULL_PATH. Available starting with Core v 4.3.0. |
EDITOR_PATH | EditorPath | Location of the directory with the FCKEditor , relative to FULL_PATH (usually "/core/editor/ "). Available starting with Core v 4.3.2.
|
WRITEABLE_BASE | WriteablePath | Directory into which the server has permissions to write (usually "/system ").
|
APPLICATION_CLASS | ApplicationClass | Class that's used to create an Application object, for example "EApplication ".
|
APPLICATION_PATH | ApplicationPath | Location of the file with the class indicated in APPLICATION_CLASS, relative to the root of the site (with the "/ " character in front), for example "/custom/units/sections/e_application.php ".
|