The following are some useful global function available in the generated code for you to work with server events easily:
``Get()``
``Get(string $name, mixed $default = null): mixed``
Get a value from ``$_GET``. If the value is not set, the default value ``$default`` (``null`` by default) is returned.
``Post()``
``Post(string $name, mixed $default = null): mixed``
Get a value from ``$_POST``. If the value is not set, the default value ``$default`` (``null`` by default) is returned.
``Param()``
``Param(string $name, mixed $default = null): mixed``
Get a value from ``$_POST``. If not set, get the value from ``$_GET``. If still not set, the default value ``$default`` (``null`` by default) is returned.
``Config()``
``Config(mixed ...$args): mixed``
Get/Set config. If value is of array type, dot notation is supported.
``Log()``
``Log(string $msg, array $context = []): void``
Log debug information to the log file. The first argument ``$message`` is a string or an object with a ``__toString()`` method, see [Message](https://www.php-fig.org/psr/psr-3/#12-message) for details.
Note that the optional second argument ``$context`` is an ARRAY for adding extra information along the textual message, the array can contain anything. A given value in the context MUST NOT throw an exception nor raise any php error, warning or notice. See [Context](https://www.php-fig.org/psr/psr-3/#13-context) for details.
``Route()``
``Route(int|string|null $idx = null): string|array|null``
Get the route value by index (nth, 0-based) or by name. If ``$i`` unspecified, all route values are returned as array.
For example, if you make a request to API like ``/api/hello/world``, the parameters are ``hello/world``, the first value, ``Route(0)``, is the action name "hello", the second value, ``Route(1)``, is "world".
``Conn()``
``Conn(string $dbid = "DB"): Connection``
Get the global connection object. If ``$dbname`` is not specified, it returns the connection object for the database of the project. If ``$dbname`` is specified, it returns the connection object for the specified database of a Linked Table.
``Security()``
``Security(): AdvancedSecurity``
Get the global security object
``Language()``
``Language(): Language``
Get the global language object.
``Profile()``
``Profile(array ...$args): mixed``
Get the global user profile object.
``Session()``
``Session(mixed ...$args): mixed``
Get the global session object, or get/set attribute(s).
``CurrentUser()``
``CurrentUser(): ?UserInterface``
Get current user entity.
``CurrentUserName()``
``CurrentUserName(): string``
Get current user name.
``CurrentUserEmail()``
``CurrentUserEmail(): ?string``
Get current user email. Requires [Email Field](securitysetup.html#options) enabled.
``CurrentUserID()``
``CurrentUserID(): mixed``
For used with User ID Security (see [Security Settings](securitysetup.html)). Get current User ID.
``CurrentUserLevel()``
``CurrentUserLevel(): int``
For used with User Level Security (see [Security Settings](securitysetup.html)). Get current user's User Level ID (integer). (Note NOT current user's permission as integer.)
``CurrentUserInfo()``
``CurrentUserInfo(string $fldname): mixed``
For used with Advanced Security (see [Security Settings](securitysetup.html)). Get current user's info from the user table. The argument is the field name in the user table.
``CurrentPageID()``
``CurrentPageID(): string``
Get current page ID. A page ID identifies the page type, it can be "list", "view", "add", "edit", "delete", "search", etc.
``CurrentPage()``
&CurrentPage(): ?object
Get current page object.
``CurrentPageName()``
``CurrentPageName(): string``
Get current page (route) name without path.
``CurrentPageTitle()``
``CurrentPageTitle(?string $value = null): string``
Get/Set current page title.
``CurrentTable()``
&CurrentTable(): ?DbTablebase
Get current table object.
``CurrentTableName()``
``CurrentTableName(): string``
Get current table name.
``CurrentLanguageID()``
``CurrentLanguageID(): string``
Get current language ID.
``Page()``
&Page(string $name = ""): ?object
Get page object of another table in the page, e.g. the page object of the master table or detail table. If ``$tablename`` is not specified, it returns ``CurrentPage()``.
``Container()``
``Container(mixed ...$args): mixed``
Get (or create if not exist) object.
``IsLoggedIn()``
``IsLoggedIn(): bool``
For used with Advanced Security (see [Security Settings](securitysetup.html)). Get the login status of the current user.
``IsAdmin()``
``IsAdmin(): bool``
For used with Advanced Security (see [Security Settings](securitysetup.html)). Check if the current user is an administrator.
``IsExport()``
``IsExport(string $format = ""): bool``
Check if the page is exporting data.
``ExecuteQuery()``
``ExecuteQuery(string $sql, Connection|string|null $c = null): \Doctrine\DBAL\Result``
Executes SELECT statement and returns the [Doctrine\DBAL\Result](https://github.com/doctrine/dbal/blob/3.6.x/src/Result.php) instance for accessing the results by [fetch API](https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/data-retrieval-and-manipulation.html#using-prepared-statements).
``ExecuteStatement()``
``ExecuteStatement(string $sql, Connection|string|null $c = null): int``
Executes UPDATE, INSERT, or DELETE statements and returns number of rows affected.
``ExecuteRow()``
``ExecuteRow(string $sql, Connection|string|null $c = null, int $mode = \PDO::FETCH_ASSOC): mixed``
Executes the query, and returns the first row as an array.
``ExecuteRows()``
``ExecuteRows(string $sql, Connection|string|null $c = null, int $mode = \PDO::FETCH_ASSOC): array|false``
Executes the query, and returns the rows as an array.
``ExecuteScalar()``
``ExecuteScalar(string $sql, Connection|string|null $c = null): mixed``
Executes the query, and returns the first column of the first row.
``ExecuteHtml()``
``ExecuteHtml(string $sql, ?array $options = null, Connection|string|null $c = null): string``
Executes the query, and returns the data as HTML table. See source code for options.
``ExecuteJson()``
``ExecuteJson(string $sql, array|bool|null $options = null, Connection|string|null $c = null): string``
Executes the query, and returns the data as JSON. See source code for options.
``QueryBuilder()``
``QueryBuilder(string $dbid = "DB"): QueryBuilder``
Create a [QueryBuilder](https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/query-builder.html) for the database connection.
``Insert()``
``Insert(string $table): QueryBuilder``
Create a [QueryBuilder](https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/query-builder.html) of INSERT statement for the specified table.
Also see ``GetFieldParameterType()`` below.
``Update()``
``Update(string $table): QueryBuilder``
Create a [QueryBuilder](https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/query-builder.html) of UPDATE statement for the specified table.
Also see ``GetFieldParameterType()`` below.
``Delete()``
``Delete(string $table): QueryBuilder``
Create a [QueryBuilder](https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/query-builder.html) of DELETE statement for the specified table.
Also see ``GetFieldParameterType()`` below.
``GetFieldParameterType()``
``GetFieldParameterType(string $table, string $field): string|int``
Get the [parameter type](https://github.com/doctrine/dbal/blob/3.6.x/src/ParameterType.php) of a field.
``EntityManager()``
``EntityManager(string $dbid = "DB"): EntityManager``
Get the [EntityManager](https://www.doctrine-project.org/projects/doctrine-orm/en/3.2/reference/architecture.html#the-entitymanager) object.
If ``$dbname`` is not specified, it returns the entity manager object for the database of the project. If ``$dbname`` is specified, it returns the entity manager object for the specified database of a Linked Table.
For example, if the table is named "Users", the entity class name is the singular form "User". The class is ``Entity\User`` under the namespace of the project.
``SetClientVar()``
``SetClientVar(string $key, mixed $value): void``
Pass server side data to client side as a property of the ``ew.vars`` object.
``CreateLoginLink()``
``CreateLoginLink(UserInterface $user, ?int $lifetime = null): LoginLinkDetails``
Create a passwordless [Login Link](authentication.html?id=login-link).
``IsGranted()``
``IsGranted(mixed $attributes, mixed $subject = null): bool``
Check if the attributes are granted against the current authentication token and optionally supplied subject, e.g.
``IsImpersonator()``
``IsImpersonator(): bool``
Check if the current user is impersonating another user, e.g.
``OriginalUser()``
``OriginalUser(): ?UserInterface``
Get the original user when impersonating another user, e.g.
``AddDebugMessage()``
``AddDebugMessage(mixed $message, string $label = "info", bool $isString = true): void``
Write your own debug messages and output to the "Messages" panel of the debug bar. If the data you pass to the first argument ``$message`` is not string, you should set the third argument ``$isString`` as ``false``, then the function will try to dump the data automatically.
``Nonce()``
``Nonce(): string``
Returns nonce attribute if [Use nonce (strict CSP)](tools.html?id=use-nonce-strict-csp) is enabled, e.g. ``nonce="mDFOblRcXBin0EPgL3bInkIQ"``.
``SendSmsNotification()``
``SendSmsNotification(#[\SensitiveParameter] string $phone, string $content, mixed $region = null, int $format = 0): bool|string``
Send SMS notification. Note that the [SmsNotifier](extension.html?id=additional-extensions-and-custom-view-tags-for-registered-users) extension(for registered users only) must be enabled and you must subscribe to a third party SMS service and retrieve the credentials for the integration.
``SendEmailNotification()``
``SendEmailNotification(#[\SensitiveParameter] string $email, string $subject, string $content): bool|string``
Send simple ext-based email notification. Note that the [Email Settings](phpsetup.html?id=email-settings) must be properly set up.
``SendEmail()``
``SendEmail(string $fromEmail,``
`` string $toEmail,``
`` string $ccEmail,``
`` string $bccEmail,``
`` string $subject,``
`` string $mailContent,``
`` string $format = "html",``
`` string $charset = EMAIL_CHARSET,``
`` int|string $priority = 3,``
`` array $attachments = [],``
`` array $images = []``
``): string|bool``
Send email. Note that:
1. [Email Settings](phpsetup.html?id=email-settings) must be properly set up.
1. If you send attachments, you should provide full paths, or you can use relative paths if you place the images in the global [upload folder](phpsetup.html?id=file-upload). If you provide the attachment content as string, you can use
["filename" => $filename, "content" => $content]
instead of file path for that attachment.
1. If you embed images, you should provide full paths, or you can use relative paths if you place the images in the global [upload folder](phpsetup.html?id=file-upload). Then you can use ``

`` in your email content, where ``{ContentId}`` can be obtained by ``GetContentId($image)``.
``AddListener()``
``AddListener(string $eventName, callable|array $listener, int $priority = 0)``
For use with [Event Listeners](customscripts.html?id=event-listeners). The ``AddListener()`` method takes up to three arguments:
1. The event name (string) that this listener wants to listen to;
1. A PHP callable that will be executed when the specified event is dispatched;
1. An optional priority, defined as a positive or negative integer (defaults to 0). The higher the number, the earlier the listener is called. If two listeners have the same priority, they are executed in the order that they were added to the dispatcher.