### Initial Trongate Welcome Controller Setup Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0070Assets/0020basic_example_part_1.html This snippet shows the initial structure of the `Welcome.php` controller file, which is part of a fresh Trongate web application installation. It includes a basic `index` method responsible for loading the 'welcome' view. For brevity, standard PHP elements like access modifiers and type hinting are omitted. ```php view("welcome"); } } ``` -------------------------------- ### Basic HTML Webpage Structure Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This is a standard HTML5 document structure, serving as a foundational starting point for any webpage within a Trongate application before integrating Trongate CSS. ```HTML Document

Hello, Trongate CSS!

``` -------------------------------- ### Complete Trongate CSS Boilerplate HTML Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This comprehensive HTML template includes the essential document structure, base URL configuration, and stylesheet link, providing a ready-to-use starting point for Trongate CSS development. ```HTML Document

Hello, Trongate CSS!

``` -------------------------------- ### Include Trongate MX Files and Configure Base URL Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0010Introduction/0020trongate_mx_quick_start.html This snippet demonstrates how to include the necessary Trongate MX JavaScript (trongate-mx.js) and CSS (trongate.css) files into your HTML template. It also illustrates the benefit of using a tag to simplify relative file paths, making URLs cleaner and more maintainable. ```html ``` ```html ``` ```html ``` -------------------------------- ### PHP: Example Usage of create_directory() Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/create_directory.html Practical examples demonstrating how to use the `create_directory()` function in PHP. These examples cover creating directories with default settings, custom permissions, and handling exceptions for restricted paths. ```PHP // Example 1: Creating a directory with default permissions and recursive flag try { $file = new File(); $success = $file->create_directory('/path/to/new_directory'); if ($success) { echo "Directory created or already exists."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 2: Creating a directory with custom permissions and non-recursive flag try { $file = new File(); $success = $file->create_directory('/path/to/new_directory', 0777, false); if ($success) { echo "Directory created or already exists."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 3: Handling restricted paths try { $file = new File(); $file->create_directory('/path/to/restricted/directory'); } catch (Exception $e) { echo "Error: " . $e->getMessage(); // Output: \"Access to this path is restricted: /path/to/restricted/directory\" } ``` -------------------------------- ### Locating Trongate Configuration File Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This snippet shows the default file path for the `config.php` file, which is responsible for defining core application constants like `BASE_URL`. ```Plain Text public/ config/ config.php ``` -------------------------------- ### PHP Examples: Resizing and Cropping Images Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Image_Class/resize_and_crop.html Practical PHP examples demonstrating how to use the `resize_and_crop()` method to process images, including handling different aspect ratios and error scenarios. ```PHP try { // Load an image $this->image->load('path/to/image.jpg'); // Resize and crop it to 200x200 pixels $this->image->resize_and_crop(200, 200); // Save the modified image $this->image->save('path/to/output.jpg'); echo "Image resized and cropped successfully."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP try { $this->image->load('path/to/landscape.jpg'); // Resize and crop to 300x300 pixels $this->image->resize_and_crop(300, 300); // Save the modified image $this->image->save('path/to/output_square.jpg'); echo "Landscape image resized and cropped to square successfully."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP try { $this->image->load('path/to/portrait.jpg'); // Resize and crop to 800x200 pixels (banner dimensions) $this->image->resize_and_crop(800, 200); // Save the modified image $this->image->save('path/to/output_banner.jpg'); echo "Portrait image resized and cropped to banner dimensions successfully."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Loading Trongate CSS Stylesheet Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This snippet shows how to link the `trongate.css` stylesheet to an HTML webpage by adding a `` element to the `` section, enabling Trongate's default styling. ```HTML ``` -------------------------------- ### PHP: File::move Method Example Usage Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/move.html Provides practical examples demonstrating how to use the `File::move` method in PHP, including basic file movement, moving multiple files in a loop, and handling exceptions for restricted paths or failed operations. These examples illustrate best practices for integrating the `move` method into applications. ```php // Example 1: Moving a file to a new location try { $file = new File(); $success = $file->move('/path/to/source/file.txt', '/path/to/destination/file.txt'); if ($success) { echo "File moved successfully."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```php // Example 2: Moving multiple files in a loop $files_to_move = [ '/path/to/source/file1.txt' => '/path/to/destination/file1.txt', '/path/to/source/file2.jpg' => '/path/to/destination/file2.jpg' ]; $file = new File(); foreach ($files_to_move as $source => $destination) { try { $file->move($source, $destination); echo "Moved $source to $destination successfully.\n"; } catch (Exception $e) { echo "Failed to move $source: " . $e->getMessage() . "\n"; } } ``` ```php // Example 3: Handling restricted paths try { $file = new File(); $file->move('/path/to/restricted/file.txt', '/path/to/destination/file.txt'); } catch (Exception $e) { echo "Error: " . $e->getMessage(); // Output: "Access to this path is restricted: /path/to/restricted/file.txt" } ``` -------------------------------- ### Creating a Simple HTML View File for Trongate Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0070Assets/0020basic_example_part_1.html This snippet provides the HTML code for a basic view file. This file, intended to be loaded by the `hello` method in the `Welcome` controller, displays a 'Hello World' message within `

` tags, serving as a simple example of a Trongate view. ```html Document

Hello World

``` -------------------------------- ### Create a Trongate MX API Endpoint Returning HTML Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0010Introduction/0020trongate_mx_quick_start.html This PHP snippet demonstrates how to create a simple API endpoint within a Trongate controller. The `get_message` function returns pure HTML content, showcasing Trongate MX's ability to handle HTML responses directly from the server, rather than requiring JSON. ```php Hello from the API!'; echo '

This is pure HTML being returned from the server.

'; echo '

The time is: '.date('H:i:s').'

'; } } ``` -------------------------------- ### PHP File Copy Examples Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/copy.html Practical examples demonstrating how to use the `copy()` method in PHP, including basic file copying, handling multiple files in a loop, and catching exceptions for restricted paths. ```PHP // Example 1: Copying a file to a new location try { $file = new File(); $success = $file->copy('/path/to/source/file.txt', '/path/to/destination/file.txt'); if ($success) { echo "File copied successfully."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP // Example 2: Copying multiple files in a loop $files_to_copy = [ '/path/to/source/file1.txt' => '/path/to/destination/file1.txt', '/path/to/source/file2.jpg' => '/path/to/destination/file2.jpg', ]; $file = new File(); foreach ($files_to_copy as $source => $destination) { try { $file->copy($source, $destination); echo "Copied $source to $destination successfully.\n"; } catch (Exception $e) { echo "Failed to copy $source: " . $e->getMessage() . "\n"; } } ``` ```PHP // Example 3: Handling restricted paths try { $file = new File(); $file->copy('/path/to/restricted/file.txt', '/path/to/destination/file.txt'); } catch (Exception $e) { echo "Error: " . $e->getMessage(); // Output: "Access to this path is restricted: /path/to/restricted/file.txt" } ``` -------------------------------- ### PHP Example: Configure Trongate Filezone Uploader Settings Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_filezone/uploader.html This PHP example demonstrates how to implement the `_init_filezone_settings` method within a Trongate module's controller. This method is crucial for defining the specific settings for the Filezone uploader, such as the target module, file destination, maximum file size, and image dimensions. ```PHP public function _init_filezone_settings() { $data['targetModule'] = 'tasks'; $data['destination'] = 'tasks_pictures'; $data['max_file_size'] = 1200; $data['max_width'] = 2500; $data['max_height'] = 1400; $data['upload_to_module'] = true; return $data; } ``` -------------------------------- ### Locating Trongate CSS File Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This snippet shows the default file path for the `trongate.css` stylesheet within a Trongate application, located in the public CSS directory. ```Plain Text public/ css/ trongate.css ``` -------------------------------- ### Dynamic Routing with `(:all)` Wildcard Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0040Understanding_Routing/0028custom_routing_patterns.html This example demonstrates the correct way to implement dynamic routing using the `(:all)` wildcard. It allows the route to match any URL that starts with 'nice-segment' and captures all subsequent segments, routing them to 'ugly_segment'. ```PHP 'nice-segment/(:all)' => 'ugly\_segment/$all' ``` -------------------------------- ### Example: Executing a SQL CREATE TABLE statement with Trongate's exec() Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Model_Class/exec.html This example demonstrates how to use Trongate's `exec()` method to create a new table named `example_table` in the database. The SQL statement defines columns for `id`, `name`, and `created_at`. ```PHP $sql = "CREATE TABLE example_table ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"; $this->model->exec($sql); ``` -------------------------------- ### PHP: Example Usage of return_file_info Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Utilities_Helpers/return_file_info.html This example demonstrates how to use the `return_file_info` function in PHP to extract and display the file name and extension from a sample file path. It shows how to access the 'file_name' and 'file_extension' keys from the returned associative array. ```PHP $file_info = return_file_info("/path/to/your/file.jpg"); echo "File Name: " . $file_info['file_name'] . "\n"; echo "File Extension: " . $file_info['file_extension'] . "\n"; // Output: // File Name: file // File Extension: .jpg ``` -------------------------------- ### PHP Example: Retrieving and Displaying All Table Names Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Model_Class/get_all_tables.html This PHP example demonstrates how to call the `get_all_tables()` method on a model instance to retrieve all database table names and then display them as a JSON response. ```PHP // Retrieve all table names from the database $tables = $this->model->get_all_tables(); // Display the table names json($tables); ``` -------------------------------- ### APIDOC: Trongate get() Method Reference Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Model_Class/get.html Detailed API documentation for the `get()` method, including its signature, purpose, parameters, and return value. ```APIDOC get() method: Signature: public function get(?string $order_by = null, ?string $target_tbl = null, ?int $limit = null, int $offset = 0): array Description: Retrieves rows from a database table based on optional parameters. This method constructs and executes an SQL query to fetch rows from the specified table, ordering them as specified, with optional limits and offsets. Parameters: - order_by: Type: string|null Description: The column to order results by. Default is 'id'. Default: 'id' Required: No - target_tbl: Type: string|null Description: The name of the database table to query. Default is derived from the first URL segment. Default: 'First URL segment' Required: No - limit: Type: int|null Description: The maximum number of results to return. Default is null. Default: null Required: No - offset: Type: int Description: The number of rows to skip before fetching results. Default is 0. Default: 0 Required: No Return Value: Type: array Description: An array of objects representing the fetched rows. ``` -------------------------------- ### Example Usage: Accessing the manage page Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_pages/manage.html Illustrates how to access the `manage` page within the Trongate application by navigating to its URL. ```Application Usage // The 'manage' page can be loaded by navigating to 'trongate_pages/manage'. ``` -------------------------------- ### Full Template Example Using Partials Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0100Templates_and_themes/0030template_partials.html This example presents the same HTML template structure as before, but it integrates a partial for the footer section. This showcases how `Template::partial()` can be used to modularize a template. ```vf Document
Acme Web Development Ltd
``` -------------------------------- ### Example Trongate Template File Structure Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0100Templates_and_themes/0025how_template_work_with_views.html Provides a complete example of a Trongate template file, demonstrating the placement of `Template::display($data)` within the HTML structure to integrate view content. ```vf My Site
``` -------------------------------- ### PHP `upload()` Method Usage Examples Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/upload.html Practical examples demonstrating how to use the `upload()` method for various scenarios, including basic uploads, module-specific uploads, and handling multiple files with error management. ```PHP // Example 1: Uploading a file to a specific directory try { $file = new File(); $config = [ 'destination' => 'uploads/images', 'make_rand_name' => true ]; $uploaded_file = $file->upload($config); echo "File uploaded successfully: " . $uploaded_file['file_name']; } catch (Exception $e) { echo "Upload failed: " . $e->getMessage(); } ``` ```PHP // Example 2: Uploading a file to a module's assets directory try { $file = new File(); $config = [ 'destination' => 'profile_pictures', 'upload_to_module' => true, 'target_module' => 'users' ]; $uploaded_file = $file->upload($config); echo "File uploaded to module successfully: " . $uploaded_file['file_path']; } catch (Exception $e) { echo "Upload failed: " . $e->getMessage(); } ``` ```PHP // Example 3: Handling multiple file uploads $files_to_upload = ['file1.jpg', 'file2.png']; foreach ($files_to_upload as $file_name) { try { $file = new File(); $config = [ 'destination' => 'uploads/documents', 'make_rand_name' => false ]; $uploaded_file = $file->upload($config); echo "Uploaded: " . $uploaded_file['file_name'] . "\n"; } catch (Exception $e) { echo "Error uploading $file_name: " . $e->getMessage() . "\n"; } } ``` -------------------------------- ### PHP Examples for Writing and Appending File Data Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/write.html Illustrative PHP examples demonstrating how to use the `write()` method to overwrite existing files, append data to files, and write array data by converting it to a string. Each example includes error handling using try-catch blocks. ```PHP // Example 1: Writing data to a file (overwrite) try { $file = new File(); $success = $file->write('/path/to/file.txt', 'Hello, world!'); if ($success) { echo "Data written successfully."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 2: Appending data to a file try { $file = new File(); $success = $file->write('/path/to/file.txt', 'Appended text.', true); if ($success) { echo "Data appended successfully."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 3: Writing an array to a file try { $file = new File(); $data = ['line1', 'line2', 'line3']; $success = $file->write('/path/to/file.txt', implode("\\n", $data)); if ($success) { echo "Array data written successfully."; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### PHP: Example Usage of `upload()` Method Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Image_Class/upload.html Demonstrates how to use the `upload()` method in PHP, including examples for uploading images with resizing and thumbnail generation, as well as a simpler upload without thumbnails. It also shows proper error handling using a try-catch block and the importance of calling `destroy()`. ```PHP // Example 1: Uploading an image with resizing and thumbnail generation $config = [ 'destination' => 'uploads/images/', 'max_width' => 1200, 'max_height' => 1200, 'thumbnail_dir' => 'uploads/thumbnails/', 'thumbnail_max_width' => 120, 'thumbnail_max_height' => 120, 'upload_to_module' => true, 'make_rand_name' => true ]; try { $file_info = $this->image->upload($config); $this->image->destroy(); // Free up memory after processing echo 'File uploaded successfully. Details: '; print_r($file_info); } catch (Exception $e) { echo 'Upload failed: ' . $e->getMessage(); } // Example 2: Uploading an image without thumbnail generation $config = [ 'destination' => 'uploads/images/', 'max_width' => 800, 'max_height' => 800, 'upload_to_module' => false, 'make_rand_name' => false ]; try { $file_info = $this->image->upload($config); $this->image->destroy(); // Free up memory after processing echo 'File uploaded successfully. Details: '; print_r($file_info); } catch (Exception $e) { echo 'Upload failed: ' . $e->getMessage(); } ``` -------------------------------- ### Complete Trongate View File Example with form_open() Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0130Form_Handling/0012creating_forms.html Provides a full example of a Trongate view file, demonstrating the correct usage of PHP opening and closing tags when incorporating `form_open()` and other PHP logic within the HTML structure. ```vf

Create New Task

``` -------------------------------- ### Trongate Initial Database Schema and Data (setup.sql) Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0020Quick_Start/0030installing_trongate_using_github.html This SQL script creates all necessary tables for a Trongate application, including administrators, comments, pages, tokens, and users. It also inserts initial data for an admin user and a default homepage, setting up the basic structure for the application's database. ```SQL SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; CREATE TABLE IF NOT EXISTS `trongate_administrators` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(65) DEFAULT NULL, `password` varchar(60) DEFAULT NULL, `trongate_user_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `trongate_administrators` (`id`, `username`, `password`, `trongate_user_id`) VALUES (1, 'admin', '$2y$11$SoHZDvbfLSRHAi3WiKIBiu.tAoi/GCBBO4HRxVX1I3qQkq3wCWfXi', 1); CREATE TABLE IF NOT EXISTS `trongate_comments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `comment` text DEFAULT NULL, `date_created` int(11) DEFAULT 0, `user_id` int(11) DEFAULT NULL, `target_table` varchar(125) DEFAULT NULL, `update_id` int(11) DEFAULT NULL, `code` varchar(6) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `trongate_pages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `url_string` varchar(255) DEFAULT NULL, `page_title` varchar(255) DEFAULT NULL, `meta_keywords` text DEFAULT NULL, `meta_description` text DEFAULT NULL, `page_body` text DEFAULT NULL, `date_created` int(11) DEFAULT NULL, `last_updated` int(11) DEFAULT NULL, `published` tinyint(1) DEFAULT NULL, `created_by` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `trongate_pages` (`id`, `url_string`, `page_title`, `meta_keywords`, `meta_description`, `page_body`, `date_created`, `last_updated`, `published`, `created_by`) VALUES (1, 'homepage', 'Homepage', '', '', '\n\nIt Totally Works!\n=================\n\n\n\n\n\n _Congratulations!_ You have successfully installed Trongate. **This is your homepage.** Trongate was built with a focus on lightning-fast performance, while minimizing dependencies on third-party libraries. By adopting this approach, Trongate delivers not only exceptional speed but also rock-solid stability.\n\n\n **You can change this page and start adding new content through the admin panel.**\n\n\n\nGetting Started\n---------------\n\n\n\n To get started, log into the [admin panel](\"[website]tg-admin\"). From the admin panel, you\'ll be able to easily edit _this_ page or create entirely _new_ pages. The default login credentials for the admin panel are as follows:\n\n\n* Username: **admin**\n* Password: **admin**\n\n\n\n\n Admin Panel\n Documentation\n\n\n\nAbout Trongate\n--------------\n\n\n\n [Trongate](\"https://trongate.io/\") is an open source project, written in PHP. The GitHub repository for Trongate is [here](\"https://github.com/trongate/trongate-framework\"). Contributions are welcome! If you\'re interested in learning how to build custom web applications with Trongate, a good place to start is The Learning Zone. The URL for the Learning Zone is: [https://trongate.io/learning-zone](\"https://trongate.io/learning-zone\"). **If you enjoy working with Trongate, all we ask is that you give Trongate a star on [GitHub](\"https://github.com/trongate/trongate-framework\").** It really helps!\n\n\n Finally, if you run into any issues or you require technical assistance, please do visit our free Help Bar, which is at: [https://trongate.io/help_bar](\"https://trongate.io/help_bar\").\n\n', 1723807486, 0, 1, 1); CREATE TABLE IF NOT EXISTS `trongate_tokens` ( `id` int(11) NOT NULL AUTO_INCREMENT, `token` varchar(125) DEFAULT NULL, `user_id` int(11) DEFAULT 0, `expiry_date` int(11) DEFAULT NULL, `code` varchar(3) DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `trongate_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(32) DEFAULT NULL, `user_level_id` int(11) DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `trongate_users` (`id`, `code`, `user_level_id`) VALUES (1, 'Tz8tehsWsTPUHEtzfbYjXzaKNqLmfAUz', 1); CREATE TABLE IF NOT EXISTS `trongate_user_levels` ( `id` int(11) NOT NULL AUTO_INCREMENT, `level_title` varchar(125) DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO `trongate_user_levels` (`id`, `level_title`) VALUES (1, 'admin'); COMMIT; ``` -------------------------------- ### PHP Example Usage of _pre_insert() function Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_comments/_pre_insert.html Demonstrates how to invoke the `_pre_insert()` function with a sample input array and inspect the structure of the processed output. ```PHP $input = [ 'token' => 'some_token_string', 'params' => [ 'user_id' => 123, 'date_created' => 1621105200, 'code' => 'abc123' ] ]; $processed_input = _pre_insert($input); var_dump($processed_input); /* Output: array(1) { ["params"]=> array(3) { ["user_id"]=> int(123) ["date_created"]=> int(1621242005) ["code"]=> string(6) "xY8zBh" } }*/ ``` -------------------------------- ### Example Trongate MX Modal with AJAX Handling Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0050UI_Enhancements/0079building_dynamic_modals.html Demonstrates how to create a dynamic modal using `mx-build-modal` combined with `mx-close-on-success` and `mx-animate-success` for AJAX response handling. Examples are provided for both Trongate PHP View Files and pure HTML. ```PHP 'title_boss/attempt_add_new_title', 'mx-build-modal' => json_encode([ 'id' => 'add-element-modal', 'width' => '460px', 'margin-top' => '5vh', 'showCloseButton' => 'true' ]), 'mx-close-on-success' => 'true', 'mx-animate-success' => 'true' ]; echo form_button('add_new_title_btn', ' Attempt Add New Title', $attr); ?> ``` ```HTML ``` -------------------------------- ### Example Usage of load() function in PHP Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Utilities_Helpers/load.html Demonstrates how to call the `load()` function with a template file and optional data. ```php load("template_file.php", ['variable' => 'value']); ``` -------------------------------- ### Make a Basic HTTP GET Request with Guzzle Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0050Controllers/0050using_packagist_with_trongate.html Use the Guzzle client to send a GET request to a specified URL. The response body can then be retrieved and processed, for example, by echoing its content. ```php $response = $client->request('GET', 'https://api.example.com/data'); echo $response->getBody(); ``` -------------------------------- ### Trongate Welcome Module index() Method Implementation Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/welcome/index.html Shows the current implementation of the Welcome module's index method, which loads and displays the 'trongate_pages' module to render the homepage. ```PHP /** * Renders the (default) homepage for public access. * * @return void */ public function index(): void { $this->module('trongate_pages'); $this->trongate_pages->display(); } ``` -------------------------------- ### PHP: Example Usage of nice_price() Function Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/String_Helpers/nice_price.html Demonstrates how to use the `nice_price` function with different inputs and shows the expected output. ```PHP echo nice_price(123456.00); // Output: 123,456 echo nice_price(123456.78, '$'); // Output: $123,456.78 ``` -------------------------------- ### Render Simple 'Hello World' Homepage in Trongate Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/welcome/index.html Demonstrates how to render a simple 'hello world' message directly when the application's default homepage is loaded using the `index()` method. ```PHP /** * Renders the (default) homepage for public access. * * @return void */ public function index(): void { echo 'hello world'; } ``` -------------------------------- ### Example Usage of extract_content in PHP Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/String_Helpers/extract_content.html This example demonstrates how to use the `extract_content` function to extract a specific substring from a larger string using defined start and end delimiters. It shows the input string, delimiters, and the resulting extracted content. ```PHP $string = "Hello, start here and end here, thanks."; $start_delim = "start here"; $end_delim = "end here"; $extracted = $this->extract_content($string, $start_delim, $end_delim); // $extracted will be " and " ``` -------------------------------- ### PHP: Examples of Image Scaling with scale() Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Image_Class/scale.html Practical PHP examples demonstrating how to use the `scale()` method to resize images to different percentages (50%, 150%) and how to perform batch scaling for multiple images, including error handling and memory management. ```PHP try { // Load an image $this->image->load('path/to/image.jpg'); // Scale the image to 50% of its original size $this->image->scale(50); // Save the scaled image $this->image->save('path/to/scaled_image.jpg'); // Free up memory after saving $this->image->destroy(); echo "Image scaled successfully to 50% of its original size."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP try { $this->image->load('path/to/image.jpg'); // Scale the image to 150% of its original size $this->image->scale(150); // Save the scaled image $this->image->save('path/to/enlarged_image.jpg'); // Free up memory after saving $this->image->destroy(); echo "Image scaled successfully to 150% of its original size."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP $image_files = ['image1.jpg', 'image2.jpg', 'image3.jpg']; foreach ($image_files as $file) { try { // Load an image $this->image->load("path/to/$file"); // Scale the image to 75% of its original size $this->image->scale(75); // Save the scaled image $this->image->save("path/to/scaled_$file"); // Free up memory after saving $this->image->destroy(); echo "Scaled and saved $file successfully.\n"; } catch (Exception $e) { echo "Error processing $file: " . $e->getMessage() . "\n"; } } ``` -------------------------------- ### PHP Example: Invoking Trongate Pages reset() Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_pages/reset.html A practical PHP example demonstrating how to call the `reset()` method within the Trongate framework. It illustrates the standard procedure for loading a module (`trongate_pages`) and executing its methods to restore the default homepage. ```PHP $this->module('trongate_pages'); $this->trongate_pages->reset(); ``` -------------------------------- ### Example URL for Trongate Child Module Method Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0084Parent_And_Child_Modules/0010understanding_parent_and_child_modules.html This concrete example demonstrates how to access the 'display' method of an 'accessories' child module, which is nested within a 'cars' parent module, using Trongate's URL routing convention. ```php http://your-domain.com/cars-accessories/display ``` -------------------------------- ### PHP Example: Get Current URL Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/URL_Helpers/current_url.html Demonstrates how to call the `current_url()` function in PHP and displays its output. ```php echo current_url(); // Output: http://example.com/current_page ``` -------------------------------- ### Adding a New Method to Trongate Welcome Controller Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0070Assets/0020basic_example_part_1.html This code demonstrates how to extend the `Welcome.php` controller by adding a new method named `hello`. This new method is designed to load a simple view file, which will display a 'hello world' message, illustrating how to add new functionalities to existing controllers. ```php view("welcome"); } function hello() { $this->view("hello"); } } ``` -------------------------------- ### PHP Examples for File Reading with read() Method Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/read.html Practical PHP examples demonstrating how to use the `read()` method to retrieve content from text and JSON files. Includes error handling using try-catch blocks for scenarios like file not found, read failures, and restricted path access. ```php // Example 1: Reading a text file try { $file = new File(); $content = $file->read('/path/to/file.txt'); echo $content; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 2: Reading a JSON file and decoding it try { $file = new File(); $json_content = $file->read('/path/to/data.json'); $data = json_decode($json_content, true); print_r($data); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } // Example 3: Handling restricted paths try { $file = new File(); $content = $file->read('/path/to/restricted/file.txt'); } catch (Exception $e) { echo "Error: " . $e->getMessage(); // Output: "Access to this file is restricted: /path/to/restricted/file.txt" } ``` -------------------------------- ### PHP Example: Get Only Column Names Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Model_Class/describe_table.html Illustrates how to use the `describe_table()` function with the optional parameter to fetch only the column names of a database table. ```PHP $table_name = 'users'; // Example table name // Get only column names $column_names = $this->model->describe_table($table_name, true); // Display the column names json($column_names); ``` -------------------------------- ### Render Website Template with View File for Homepage Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/welcome/index.html Demonstrates how a website template, with a corresponding view file, can be rendered when the application's default homepage is loaded via the `index()` method. ```PHP /** * Renders the (default) homepage for public access. * * @return void */ public function index(): void { $data['view_module'] = 'welcome'; $data['view_file'] = 'homepage_content'; $this->template('public', $data); } ``` -------------------------------- ### PHP post() Function Example Usage Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Form_Helpers/post.html Examples demonstrating how to use the `post()` function to retrieve raw POST data, sanitized and type-converted data, and how to handle both simple and nested JSON payloads using dot notation. ```PHP // Retrieve raw POST data $username = post('username'); // Retrieve sanitized and potentially converted POST data $age = post('age', true); // Example with type conversion $price = post('price', true); // If POST data contains '19.99', $price will be float(19.99) // If POST data contains '20', $price will be int(20) // Handling JSON data $jsonData = post('user_data'); // If POST contains JSON like '{"name": "John", "age": 30}', // $jsonData will be an array(['name' => 'John', 'age' => 30]) // Handling nested JSON data $street = post('user_data.address.street', true); // If POST contains JSON like '{"user_data": {"address": {"street": "123 Main St"}}}', // $street will be "123 Main St" (sanitized) ``` -------------------------------- ### Example URL for View File Resolution Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0100Templates_and_themes/0025how_template_work_with_views.html Illustrates a typical URL structure that triggers the view file resolution process in Trongate. ```text https://example.com/products/details/88 ``` -------------------------------- ### index() Method API Reference Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/welcome/index.html Detailed API documentation for the `index()` method, including its signature, parameters, and return type. ```APIDOC function index(): void Description: Renders the (default) homepage for public access. This method loads the 'trongate_pages' module and calls its 'display()' method to render the homepage. Parameters: This method does not take any parameters. Return Value: Type: void Description: This method does not return any value. ``` -------------------------------- ### PHP Example: Get Detailed Table Information Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Model_Class/describe_table.html Demonstrates how to use the `describe_table()` function to retrieve comprehensive structural information for a specified database table. ```PHP $table_name = 'users'; // Example table name // Get detailed information about table structure $table_info = $this->model->describe_table($table_name); // Display the information json($table_info); ``` -------------------------------- ### PHP: Get Client IP Address Example Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Utilities_Helpers/ip_address.html Demonstrates a simple usage of the `ip_address()` function in PHP to retrieve and display the client's IP address. ```PHP echo ip_address(); ``` -------------------------------- ### PHP Example: Rendering a View and Capturing Output Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Trongate_Class/view.html Demonstrates how to use the `view()` method to render a view file, pass data, and capture the output as a string for further processing. ```PHP $view_content = $this->view("my_view", ["name" => "John Doe"], true); echo $view_content; // Output: HTML content of the rendered view ``` -------------------------------- ### PHP Examples for Resizing Images to a Specific Height Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Image_Class/resize_to_height.html Demonstrates various use cases for the `resize_to_height` method in PHP, including single image resizing, batch processing, and memory management considerations. These examples show how to load, resize, save, and optionally destroy image resources. ```PHP try { // Load an image $this->image->load('path/to/image.jpg'); // Resize the image to a height of 300 pixels $this->image->resize_to_height(300); // Save the resized image $this->image->save('path/to/resized_image.jpg'); // Free up memory after saving $this->image->destroy(); echo "Image resized successfully to a height of 300 pixels."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP $image_files = ['image1.jpg', 'image2.jpg', 'image3.jpg']; foreach ($image_files as $file) { try { // Load an image $this->image->load("path/to/$file"); // Resize the image to a height of 400 pixels $this->image->resize_to_height(400); // Save the resized image $this->image->save("path/to/resized_$file"); // Free up memory after saving $this->image->destroy(); echo "Resized and saved $file successfully.\n"; } catch (Exception $e) { echo "Error processing $file: " . $e->getMessage() . "\n"; } } ``` ```PHP try { $this->image->load('path/to/image.jpg'); $this->image->resize_to_height(250); $this->image->save('path/to/resized_image.jpg'); echo "Image resized successfully. Memory will be freed automatically at script end."; } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Complete Example for Triggering and Displaying Trongate Modals Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0040cards_and_modals/0020working_with_modals.html This example demonstrates how to set up and trigger a modal. It includes a button that calls 'openModal()' with the modal's ID and the corresponding hidden modal HTML structure. It also highlights the need for a JavaScript file and initial 'display: none' styling. ```HTML ``` -------------------------------- ### Trongate MX GET Request Button with Target Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0020Core_HTTP_Operations/0030http_methods_in_trongate_mx.html This example shows how to create a button that sends an HTTP GET request using `mx-get` in Trongate MX. It includes both a Trongate View File (VF) syntax using `form_button()` and a pure HTML alternative. The `mx-target` attribute specifies that the response will be displayed in the element with `id="result"`. ```PHP 'api/get_data', 'mx-target' => '#result' ]; echo form_button('get_data_btn', 'Get Data', $attributes); ?>
``` ```HTML
``` -------------------------------- ### Implement Redirect on Success for Login Form Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0040Events_and_Responses/0075redirect_on_success.html This example shows how to apply `mx-redirect-on-success` to a login form. After a successful submission, the user will be redirected to the URL specified by the server's response. This is a common use case for guiding users to their dashboard post-login. ```php 'members/submit_login', 'mx-redirect-on-success' => 'true' ]; echo form_open('#', $form_attr); $username_attr['placeholder'] = 'Enter username here...'; echo form_input('username', '', $username_attr); $password_attr['placeholder'] = 'Enter password here...'; echo form_password('password', '', $password_attr); echo form_submit('submit_btn', 'Login'); echo form_close(); ?> ``` -------------------------------- ### API Documentation for load() function Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Utilities_Helpers/load.html Detailed API reference for the `load()` function, including its signature, parameters, and return value. ```APIDOC function load(string $template_file, ?array $data = null): void Description: Loads a template file with optional data for use within the template. Parameters: $template_file: Type: string Description: The filename of the template to load. Default: N/A $data: Type: array|null Description: (Optional) The data to be passed to the template as an associative array. Default: null Return Value: Type: void Description: This function does not return a value. ``` -------------------------------- ### Adding Base URL Element to HTML Head Source: https://github.com/trongate/trongate-docs/blob/main/trongate_css/0010Introduction/0020getting_started_with_trongate_css.html This snippet demonstrates how to add a `` HTML element to the `` section, setting its `href` attribute to the application's base URL using a PHP constant (`BASE_URL`) for dynamic path resolution. ```HTML ``` -------------------------------- ### Implicit Click Trigger for Buttons with mx-get Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0040Events_and_Responses/0070triggers_in_trongate_mx.html This example illustrates that for button elements, `mx-trigger='click'` is the default behavior. Omitting the `mx-trigger` attribute still results in the button triggering an HTTP GET request on click, as Trongate MX automatically assigns 'click' as the default trigger. ```html ``` -------------------------------- ### PHP Examples: Retrieving File Metadata with `info()` Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/info.html Demonstrates various uses of the `info()` method in PHP, including retrieving full file metadata, displaying human-readable size, and checking file permissions, all with proper exception handling. ```PHP // Example 1: Retrieving metadata for a file try { $file = new File(); $file_info = $file->info('/path/to/file.txt'); print_r($file_info); /* Output: Array ( [file_name] => file.txt [size] => 1024 [human_readable_size] => 1.00 KB [modified_time] => 1698765432 [permissions] => 33188 [readable_permissions] => 0644 [mime_type] => text/plain ) */ } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP // Example 2: Displaying human-readable file size try { $file = new File(); $file_info = $file->info('/path/to/large_file.zip'); echo "File size: " . $file_info['human_readable_size']; // Output: "File size: 123.45 MB" } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP // Example 3: Checking file permissions try { $file = new File(); $file_info = $file->info('/path/to/protected_file.txt'); echo "File permissions: " . $file_info['readable_permissions']; // Output: "File permissions: 0644" } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Define Custom Route for Numeric Wildcards (PHP) Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0040Understanding_Routing/0032custom_routing_practical_examples.html This snippet shows how to define a custom route that handles numeric wildcards in URLs. It reassigns URLs starting with 'store_items/display/' to 'laptops/display/', preserving the numeric ID. This is ideal for making product pages more descriptive and SEO-friendly while maintaining dynamic content access. ```php 'laptops/display/(:num)' => 'store_items/display/$1', ``` -------------------------------- ### Example: Loading and Using a Trongate Child Module in a Controller Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0084Parent_And_Child_Modules/0010understanding_parent_and_child_modules.html This comprehensive PHP example demonstrates loading the 'product_reviews' child module within a 'shop' parent module's controller. It shows how to call a child module method (`get_latest_reviews`) after loading, and integrate its output into a view, highlighting practical usage of nested modules. ```php module('shop-product_reviews'); // Get the latest reviews for this product $latest_reviews = $this->product_reviews->get_latest_reviews($product_id, 5); // Prepare data for the view $data['product_id'] = $product_id; $data['latest_reviews'] = $latest_reviews; $data['view_module'] = 'shop'; $data['view_file'] = 'display_product'; // Load the template, passing in the $data array $this->template('public', $data); } } ``` -------------------------------- ### API Documentation for load() method Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_Modules_Class/load.html Documents the `load()` method, detailing its signature, parameters, and return type for module instantiation within the Trongate framework. ```APIDOC function load(string $target_module): void Description: Loads a module by instantiating its controller. Parameters: $target_module (string): The name of the target module. Return Value: void: No return value. ``` -------------------------------- ### Trongate go_home() API Reference Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_administrators/go_home.html This section provides a detailed API reference for the `go_home()` function, including its signature, a description of its functionality, and information regarding its parameters and return value. ```APIDOC Function Signature: public function go_home(): void Description: Redirects to the designated dashboard home page. Parameters: This method does not take any parameters. Return Value: Type: void Description: This method does not return any value. ``` -------------------------------- ### Example Trongate config.php File (PHP) Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0040Understanding_Routing/0015homepage_routing.html This snippet shows a complete `config.php` file, including the `BASE_URL` constant, environment setting, and the default homepage routing constants. It illustrates a typical Trongate configuration for a live website. ```PHP model->get(); ``` -------------------------------- ### PHP: Set Flash Message Example Source: https://github.com/trongate/trongate-docs/blob/main/reference/helpers/Flashdata_Helpers/set_flashdata.html Example demonstrating how to use the `set_flashdata()` function to store a success message in the session. ```php set_flashdata("Your data has been saved successfully."); // This sets a flash message in the session. ``` -------------------------------- ### Invoke AJAX Requests with Trongate MX Attributes Source: https://github.com/trongate/trongate-docs/blob/main/trongate_mx/0010Introduction/0020trongate_mx_quick_start.html This snippet illustrates how to trigger AJAX requests in Trongate MX without writing any JavaScript. It shows two methods: directly using `mx-get` and `mx-target` attributes on an HTML button, and achieving the same functionality using Trongate's `form_button()` helper function in PHP. Both methods make an AJAX call to the specified endpoint and insert the returned HTML into the target element. ```html
``` ```php 'welcome/get_message', 'mx-target' => '#message-target' ]; echo form_button('fetch_btn', 'Click Me', $btn_attr); ?>
``` -------------------------------- ### PHP Example: Using _prep_comments() with Sample Data Source: https://github.com/trongate/trongate-docs/blob/main/reference/pre_installed/trongate_comments/_prep_comments.html Illustrates how to call the `_prep_comments` function in PHP with a sample array, demonstrating the input and the structure of the processed output. ```php $output = ['body' => '[{"comment":"This is a comment.","user_id":1,"date_created":1621105200,"target_table":"pages","update_id":1,"code":"abc123"}]']; $processed_output = _prep_comments($output); var_dump($processed_output); /* Output: array(1) { ["body"]=> string(134) "[{"comment":"This is a comment.","date_created":"Posted by user123 on Thursday 15th of May 2024 at 10:00:00 AM","user_id":1,"target_table":"pages","update_id":1,"code":"abc123"}]" }*/ ``` -------------------------------- ### PHP File::list_directory() Example Usage Source: https://github.com/trongate/trongate-docs/blob/main/reference/class_reference/The_File_Class/list_directory.html Examples demonstrating how to use the `list_directory` method for non-recursive, recursive, and error handling scenarios. ```PHP // Example 1: Non-recursive listing try { $file = new File(); $contents = $file->list_directory('/path/to/directory'); print_r($contents); /* Output: Array ( [0] => file1.txt [1] => file2.jpg [2] => subdirectory ) */ } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP // Example 2: Recursive listing try { $file = new File(); $contents = $file->list_directory('/path/to/directory', true); print_r($contents); /* Output: Array ( [0] => file1.txt [1] => file2.jpg [2] => subdirectory => Array ( [0] => subfile1.txt [1] => subfile2.jpg ) ) */ } catch (Exception $e) { echo "Error: " . $e->getMessage(); } ``` ```PHP // Example 3: Handling restricted paths try { $file = new File(); $contents = $file->list_directory('/path/to/restricted/directory'); } catch (Exception $e) { echo "Error: " . $e->getMessage(); // Output: "Access to this path is restricted: /path/to/restricted/directory" } ``` -------------------------------- ### Locate Trongate Database Configuration File Source: https://github.com/trongate/trongate-docs/blob/main/php_framework/0020Quick_Start/0030installing_trongate_using_github.html This snippet indicates the path to the 'database.php' file, which must be updated with your database credentials after creating a database. ```Plaintext config/ database.php ```