### Role Definition Example (PHP) Source: https://phpmaker.dev/docs2025/index_/authentication.html_id=impersonating-a-user Illustrates the convention for defining user roles in PHP, emphasizing that roles must start with the 'ROLE_' prefix. Examples include predefined roles and custom roles. ```php // Predefined roles // ROLE_USER, ROLE_SALES, ROLE_MANAGER, ROLE_DEFAULT, ROLE_ADMIN // Custom role example $user->addRole('ROLE_PRODUCT_ADMIN'); ``` -------------------------------- ### Global Code Callable Example Source: https://phpmaker.dev/docs2025/index_/generatesetup.html_id=debug This example demonstrates how to specify a callable function or static method from Global Code to be used as the start page. This provides flexibility in defining the initial user redirection. ```php // Example: MyFunction MyFunction // Example: MyClass::myStaticMethod MyClass::myStaticMethod ``` -------------------------------- ### User Role Definition Example (PHP) Source: https://phpmaker.dev/docs2025/index_/authentication.html_id=limiting-login-attempts User roles in PHPMaker must start with the 'ROLE_' prefix. This example demonstrates how custom roles like 'ROLE_PRODUCT_ADMIN' can be defined and assigned to users. ```php // Example of user roles $userRoles = ['ROLE_USER', 'ROLE_SALES', 'ROLE_PRODUCT_ADMIN']; ``` -------------------------------- ### Global Code Callable Example Source: https://phpmaker.dev/docs2025/index_/generatesetup.html_id=regeneration-by-cli-commands Illustrates how to specify a callable function or static method from Global Code as a start page in PHPMaker. This allows for dynamic redirection logic. ```php // Example callable function in Global Code function MyFunction() { // ... redirection logic ... } // Example static method in Global Code class MyClass { public static function myStaticMethod() { // ... redirection logic ... } } ``` -------------------------------- ### Test Composer Installation Source: https://phpmaker.dev/docs2025/index_/composer.html After installing Composer, this command can be used in a new command prompt to verify the installation by displaying the installed Composer version. Successful execution indicates that Composer is correctly installed and accessible via the system's PATH. ```bash composer -V ``` -------------------------------- ### Configure SAML SP Certificate and Key (SimpleSAMLphp Example) Source: https://phpmaker.dev/docs2025/index_/tools.html_id=session-time-out-countdown-period-seconds Sets up the X.509 certificate and private key files for your SAML Service Provider (SP). These are necessary for signing SAML requests and encrypting assertions, especially when using SimpleSAMLphp. ```php [ 'saml:SP', 'entityID' => 'my-entity-id', // Entity ID of your SAML SP 'privatekey' => 'saml.pem', // SAML SP X.509 certificate file, if required 'certificate' => 'saml.crt' // SAML SP private key file, if required ... ], ... ]; ?> ``` -------------------------------- ### Remote File Storage URI (Example) Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=operator-2-1 Illustrates how to specify a remote storage location using a Filesystem URI. This example uses an S3 bucket. Ensure the bucket permissions are configured for accessibility. ```plaintext s3://my-bucket/ ``` -------------------------------- ### GET /myaction/{id} Source: https://phpmaker.dev/docs2025/index_/customfile.html_id=example-1 Example of an API action defined using the `Route` attribute within a custom controller. ```APIDOC ## GET /myaction/{id} ### Description An example API action that can be accessed via the specified path. The route, methods, and name are defined using the `Route` attribute in the controller class. ### Method GET, OPTIONS ### Endpoint /myaction/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Identifier for the action. #### Query Parameters #### Request Body ### Request Example ### Response #### Success Response (200) - **(Response details depend on implementation)** #### Response Example ```json { "data": "Response from myAction" } ``` ``` -------------------------------- ### LDAP Configuration Examples Source: https://phpmaker.dev/docs2025/index_/tools.html_id=grid-scrollbar-mode Illustrative examples for configuring LDAP user authentication. These snippets demonstrate how to set various parameters like user password, default roles, UID key, extra fields, filters, DN string, and query string. Proper configuration is crucial for successful LDAP integration. ```php $config = [ 'user_password' => 'read_only_user_password', 'default_roles' => ['AUTHENTICATED_USER'], 'uid_key' => 'sAMAccountName', 'extra_fields' => ['memberOf'], 'filter' => '({uid_key}={user_identifier})', 'dn_string' => '{user_identifier}', 'query_string' => null, 'options' => [ LDAP_OPT_PROTOCOL_VERSION => 3, LDAP_OPT_REFERRALS => 0 ] ]; ``` -------------------------------- ### LDAP DN String Example Source: https://phpmaker.dev/docs2025/index_/tools.html_id=locale Demonstrates constructing the DN string for a user. ```plaintext # Example: If users have DNs like uid=einstein,dc=example,dc=com # dn_string setting would be: 'uid={user_identifier},dc=example,dc=com' ``` -------------------------------- ### GET /myaction2/{param1}/{param2} Source: https://phpmaker.dev/docs2025/index_/customfile.html_id=example-1 Another example of an API action defined using the `Route` attribute, demonstrating multiple path parameters. ```APIDOC ## GET /myaction2/{param1}/{param2} ### Description An example API action with multiple path parameters, accessible via the specified route. The route, methods, and name are defined using the `Route` attribute in the controller class. ### Method GET ### Endpoint /myaction2/{param1}/{param2} ### Parameters #### Path Parameters - **param1** (string) - Required - The first parameter for the action. - **param2** (string) - Required - The second parameter for the action. #### Query Parameters #### Request Body ### Request Example ### Response #### Success Response (200) - **(Response details depend on implementation)** #### Response Example ```json { "message": "Received param1: {param1}, param2: {param2}" } ``` ``` -------------------------------- ### PHP - Custom URL Examples for Redirects Source: https://phpmaker.dev/docs2025/index_/tablesetup.html_id=inline-copy Provides examples of valid PHP expressions for specifying custom return URLs after record operations. These examples demonstrate how to redirect to specific pages, pass field values, and link to detail tables. ```php "MyPage" "MyPage?xxx=" . urlencode($this->->CurrentValue) "orderdetailslist?action=gridadd&showmaster=orders&fk_OrderID=" . urlencode($this->OrderID->CurrentValue) "orderdetailsadd?showmaster=orders&fk_OrderID=" . urlencode($this->OrderID->CurrentValue) ``` -------------------------------- ### Example Filter Function for 'Starts With A' (PHP) Source: https://phpmaker.dev/docs2025/index_/customscripts.html_id=page_unload-1 This PHP function, intended for use in Global Code, constructs a SQL LIKE clause to filter records where a given field expression starts with the letter 'A'. It's designed to be called by a custom filter. ```php // Note: This function is already in the template, do not put it in the Global Code again. function GetStartsWithAFilter(string $FldExpression): string { return $FldExpression . " LIKE 'A%'" ; } ``` -------------------------------- ### PHPMaker Register Notification Template Example Source: https://phpmaker.dev/docs2025/index_/multilang.html_id=multi-language-property-editor Example of a Register notification template in English (en-US). It demonstrates the use of predefined variables like $From, $To, $Fields, and $ActivateLink to customize email content. The template supports HTML and PHP tags for dynamic content generation. ```php Subject: Registration Information From: To: Cc: Bcc: Format: HTML

Dear Sir/Madam,

Thank you for registering. Your information is as follow:

$field) { ?>

caption ?>: value ?>

Please click the following link to activate your account:
Activate account

Please feel free to contact us in case of further queries.

Best Regards,
Support

``` -------------------------------- ### Dynamic Upload Path Example (PHP) Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=check-duplicate-6 Demonstrates how to set a dynamic upload path based on other field values in PHP. This requires careful consideration of folder naming conventions and server permissions. The path is relative to the project folder unless a Filesystem URI is used. ```php $this->UploadPath = "uploads/" . $this->MyField->DbValue . "/"; ``` -------------------------------- ### PHP Assert Validation Example Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=add This code demonstrates the use of Symfony's validator component to validate an email address against various constraints. It covers creating constraints, validating the value, and handling validation errors. This example uses both default and custom error messages. ```PHP use Symfony\Component\Validator\Constraints as Assert; // Create not blank constraint $notBlankConstraint = new Assert\NotBlank(); // Use default error message or $notBlankConstraint = new Assert\NotBlank(message: "Empty value"); // Use custom error message // Create email constraint $emailConstraint = new Assert\Email(); // Use default error message or $emailConstraint = new Assert\Email(message: "Invalid email address"); // Use custom error message // Get the validator $validator = Validator(); // The value to validate $email = "foobar@example"; // Use the validator to validate the value $errors = $validator->validate($email, $emailConstraint); // You can pass a single constraint or an array of constraints $errors = $validator->validate($email, [$notBlankConstraint, $emailConstraint]); // Server-side validation uses the global Validate() function $errors = Validate($email, [$notBlankConstraint, $emailConstraint]); if (!$errors->count()) { // This IS a valid email address, do something } else { // This is NOT a valid email address $errorMessage = $errors[0]->getMessage(); // Returns 'Invalid email address' // Do something with the error } ``` -------------------------------- ### Dynamic Upload Path Example (PHP) Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=percent Illustrates how to set a dynamic upload path based on other field values in PHP. This allows for organizing uploaded files based on dynamic criteria. Ensure the path is a valid folder name and accessible by the web server. ```php $this->MyField->UploadPath = "uploads/" . $this->AnotherField->DbValue . "/"; ``` -------------------------------- ### PHP Validation Arguments Examples Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=custom-attributes-4 Examples of server-side PHP arguments for validation functions. Arguments are comma-separated PHP expressions. Strings require single or double quotes. Regular expressions must be quoted patterns, like '/foobar/i', referencing PHP's preg_match function. ```php // Example for string argument '"Hello World"' // Example for regular expression argument '/^[a-zA-Z0-9_]+$/i' ``` -------------------------------- ### PHPMaker Code Repository XML Example - Get Fields Source: https://phpmaker.dev/docs2025/index_/customscripts.html An example demonstrating how to define reusable code within PHPMaker's Code Repository. This snippet shows how to retrieve fields for the current table and filter them for view pages using EJS syntax. ```ejs <#+ let TABLE = DB.Tables.find(tbl => tbl.TblName == "{TblName}"), // Get the current table currentFields = TABLE.Fields.filter(f => f.FldGenerate && f.FldView); // Get the fields for the View page #> ``` -------------------------------- ### Google Sign-In Configuration Source: https://phpmaker.dev/docs2025/index_/tools.html_id=ldap-referrals Enable Google Sign-In by providing your Google Client ID and Client Secret. Ensure your Google API Console project is set up correctly with the appropriate redirect URIs. ```php return [ // ... other configurations 'google' => [ 'client_id' => 'YOUR_GOOGLE_CLIENT_ID', 'client_secret' => 'YOUR_GOOGLE_CLIENT_SECRET', // The redirect URI should be set in your Google API Console project. // Example: https://www.company.com/basepath/login/Google ] ]; ``` -------------------------------- ### PHP Custom Validation with Callback Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=add This code provides an example of using the Callback constraint in PHP for custom validation logic. It defines a `MyValidator` class with a static `validate` method that receives the value to validate, an execution context, and a payload (optional). The example shows how to reference this method in the Assert\Callback constraint. ```PHP SomeFilter->Visible = false; // Example for unregistering: // $this->SomeFilter->unregister(); ``` -------------------------------- ### LDAP Options Configuration Example Source: https://phpmaker.dev/docs2025/index_/tools.html_id=use-tabular-form-for-desktop An array of options to be passed to ldap_set_option. Some options like protocol version and referrals are set by default. ```php $ldapOptions = [ LDAP_OPT_PROTOCOL_VERSION => 3, LDAP_OPT_REFERRALS => 0, // Other custom options can be added here ]; ``` -------------------------------- ### PHP - Dynamic Return URL Examples Source: https://phpmaker.dev/docs2025/index_/tablesetup.html_id=update-table Provides examples of PHP expressions for constructing dynamic return URLs after record operations. These URLs can redirect users to custom pages, pass field values, or navigate to detail tables in specific states like grid add or edit. Ensure URLs are properly quoted and valid PHP expressions. ```php // Example 1: Redirect to a custom page "MyPage" // Example 2: Pass field values to a custom page "MyPage?xxx=" . urlencode($this->->CurrentValue) // e.g., "MyPage?ID=" . urlencode($this->ID->CurrentValue) // Example 3: Redirect to detail table's Grid-Add page after master record add "list?action=gridadd&showmaster=&fk_=" . urlencode($this->->CurrentValue) // e.g., "orderdetailslist?action=gridadd&showmaster=orders&fk_OrderID=" . urlencode($this->OrderID->CurrentValue) // Example 4: Redirect to detail table's Add page after master record add "add?showmaster=
&fk_=" . urlencode($this->->CurrentValue) // e.g., "orderdetailsadd?showmaster=orders&fk_OrderID=" . urlencode($this->OrderID->CurrentValue) ``` -------------------------------- ### Custom Edit Tag Example: Input Field with Edit Value Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=dropdown-min-width-px-1 This example illustrates how to use the {{{edit_value}}} special tag within an input field's attributes. It dynamically sets the value of an HTML input element using the field's edit value. Suitable for direct HTML integration. ```html ``` -------------------------------- ### Generate SAML Certificate and Private Key (OpenSSL) Source: https://phpmaker.dev/docs2025/index_/saml.html_id=setup-advanced-settings Demonstrates how to generate a self-signed X.509 certificate and a private key using OpenSSL. These files are required for the SAML SP and can be used for both standard and SHA-256 certificates. ```bash cd cert openssl req -newkey rsa:3072 -new -x509 -days 3652 -nodes -out saml.crt -keyout saml.pem ``` ```bash openssl req -newkey rsa:3072 -new -x509 -days 3652 -nodes -sha256 -out saml.cer -keyout saml.pem ``` -------------------------------- ### Getting Project Start Page with PROJ.StartPage (v9+) Source: https://phpmaker.dev/docs2025/index_/objectproperties.html_id=table This snippet shows how to retrieve the name of the project's start page using the PROJ.StartPage string property, available from version 9. This property defines the initial page users see upon accessing the application. ```html <#= PROJ.StartPage #> ``` -------------------------------- ### PHP Encryption Configuration Example Source: https://phpmaker.dev/docs2025/index_/tools.html_id=ldap-extra-fields-array Illustrates how to use php-encryption for sensitive data like administrator and database credentials. This requires setting an encryption key and potentially configuring the PHP CLI for encryption during generation. Beware of performance implications. ```php getMessage(); } // Example for encrypting/decrypting a file // try { // File::encryptFile('path/to/plaintext.txt', 'path/to/encrypted.txt', $encryptionKey); // File::decryptFile('path/to/encrypted.txt', 'path/to/decrypted.txt', $encryptionKey); // } catch (Exception $e) { // echo 'File encryption/decryption failed: ' . $e->getMessage(); // } ?> ``` -------------------------------- ### LDAP User Provider Configuration Examples Source: https://phpmaker.dev/docs2025/index_/tools.html_id=chart-scale-minimum-value These examples demonstrate how to configure various aspects of the LDAP user provider in PHP-Fusion. This includes setting up read-only user credentials, default roles, UID keys, and custom fields for fetching user information from an LDAP server. ```php $config["ldap_user_provider"] = [ "read_only_user_password" => "YOUR_LDAP_PASSWORD", "default_roles" => ["AUTHENTICATED"], "uid_key" => "sAMAccountName", "extra_fields" => ["memberOf", "displayName"], "ldap_filter" => "(uid={user_identifier})", "ldap_dn_string" => "ou=users,dc=example,dc=com", "ldap_query_string" => "(&(objectClass=user)(sAMAccountName={user_identifier}))", "ldap_options" => [ LDAP_OPT_PROTOCOL_VERSION => 3, LDAP_OPT_REFERRALS => 0 ] ]; ``` -------------------------------- ### Configure Custom Hyperlink Attributes in PHP (String Format) Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=dropdown-min-width-px This example demonstrates setting custom attributes for an anchor () tag in PHP using a string format within PHPMaker. While functional, this method is not recommended over the array format because duplicate attributes may be ignored by browsers. The example shows setting a 'rel' attribute. ```php $this->addCustomAttributes("rel='xxx'" ) ``` -------------------------------- ### LDAP Query String Example Source: https://phpmaker.dev/docs2025/index_/tools.html_id=locale Shows an example of an LDAP query string for searching users. ```plaintext # Example query string: '(&(uid={user_identifier})(memberOf=cn=users,ou=Services,dc=example,dc=com))' ``` -------------------------------- ### PHP Hyperlink Configuration Examples Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=custom-attributes-4 Demonstrates PHP code snippets for configuring hyperlink settings in PHP Maker. This includes examples for setting the HREF field, using original field values, specifying the target attribute, adding prefixes and suffixes, and defining custom attributes using both string and array formats. ```php MyField->HrefValue = $this->MyField->CurrentValue; $this->MyField->UseOriginalHREFValue = TRUE; // Example of setting target attribute $this->MyField->Target = "_blank"; // Example of setting prefix (string) $this->MyField->Prefix = "https://"; // Example of setting prefix with PHP variable $this->MyField->Prefix = "mypage?id="; $this->MyField->Prefix = "mypage?myfield={$this->urlEncode($this->MyField->CurrentValue)}&id="; $this->MyField->Prefix = "mypage?myfield={$this->raw(Encrypt($this->MyField->CurrentValue))}&id="; // Example of setting suffix $this->MyField->Suffix = "&field2={$this->urlEncode($this->Field2->CurrentValue)}"; // Example of setting custom attributes (string format) $this->MyField->Attributes = "rel='nofollow'"; // Example of setting custom attributes (array format - recommended) $this->MyField->Attributes = ["rel" => "nofollow", "class" => "my-link", "style" => "color: blue;"]; ?> ``` -------------------------------- ### PHPMaker EJS Example: Get and Loop Through Table Fields Source: https://phpmaker.dev/docs2025/index_/customscripts.html_id=page_unload-10 An example using EJS (Embedded JavaScript templating) within PHPMaker's Code Repository to retrieve fields for a specific table and then iterate through them to generate dynamic HTML content. It demonstrates accessing table metadata and field properties. ```ejs <#= let TABLE = DB.Tables.find(tbl => tbl.TblName == "{TblName}"), // Get the current table currentFields = TABLE.Fields.filter(f => f.FldGenerate && f.FldView); // Get the fields for the View page #> <# for (let f of currentFields) { #>
{{{caption <#= f.FldParm #>}}}
{{{value <#= f.FldParm #>}}}
<# } #> ``` -------------------------------- ### Dynamic Upload Path Example Source: https://phpmaker.dev/docs2025/index_/fieldsetup.html_id=view-tag Demonstrates how to set a dynamic upload path based on other field values. The path is evaluated before the file is displayed or saved, ensuring consistency. The path is relative to the project folder and uses forward slashes as delimiters. ```php // Example of a dynamic upload path in PHPMaker server event $this->MyField->UploadPath = "uploads/" . $this->OtherField->DbValue . "/"; ```