__get()

public function __get(string $key)

Description

Magic method that enables automatic lazy-loading of database connections and modules within model classes. Called automatically by PHP when accessing inaccessible (undefined) properties on the model object.

For database access: $this->db returns the default database connection. Alternative database groups defined in config/database.php are also accessible via their group name (e.g., $this->analytics).

For non-database properties, the method attempts to load the requested module, enabling access like $this->some_module from within model files.

Parameters

Parameter Type Description Default Required
key string The property name being accessed (e.g., 'db', 'analytics', or a module name). N/A Yes

Return Value

TypeDescription
object Returns a Db instance for database groups, or the requested module instance for module access.