__construct()
public function __construct(?string $module_name = null, ?object $caller = null)
Description
Constructor for the Validation module. Initializes the module and stores a reference to the calling controller for callback methods.
Note: The framework automatically passes the module name and caller when instantiating Validation via $this->validation. You rarely need to call this constructor manually.
Parameters
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| module_name | string|null | The module name (passed by framework for integration with Trongate module system). | null | No |
| caller | object|null | The calling controller instance, used for callback validation rules. | null | No |
Return Value
| Type | Description |
|---|---|
| void | Constructor does not return a value. |
Example Usage
PHP
<?php
// Automatic instantiation by framework (inside a controller)
class Products extends Trongate {
public function submit() {
// $this->validation is automatically a Validation instance
$this->validation->set_rules('name', 'Product Name', 'required|min_length[3]');
if ($this->validation->run()) {
// validation passed
}
}
}
// Manual instantiation (rare)
$validation = new Validation('products', $this);