### 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
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