Overview
FacturaScripts uses a flexible settings system that allows you to configure various aspects of the application. Settings are stored in the database and accessed through theSettings model and Tools helper class.
Settings Model
The Settings model is located atCore/Model/Settings.php and provides a key-value storage system grouped by setting names.
Settings Structure
- name: Identifier of the settings group (primary key)
- properties: JSON-encoded set of configuration values
Settings Properties
Settings are stored as JSON and accessed as object properties:Accessing Settings
Using Tools::settings()
The recommended way to access settings is through theTools helper:
- group: Settings group name (e.g., ‘default’)
- key: Property name within the group
- default: Optional default value if setting doesn’t exist
Direct Model Access
You can also work directly with the Settings model:Default Settings Group
The ‘default’ settings group contains system-wide configuration. Here are common settings found in the source code:Company Settings
- idempresa: Default company ID (used in
User.php:192,Empresa.php:190) - codpais: Default country code (used in
Empresa.php:113) - tipoidfiscal: Default fiscal ID type (used in
Empresa.php:116)
Warehouse Settings
- codalmacen: Default warehouse code (used in
User.php:189,User.php:476)
User Settings
- codrole: Default role assigned to new users (used in
User.php:451)
Plugin Settings
- enableupdatesbeta: Enable beta plugin updates (used in
Plugin.php:214)
Configuration via config.php
Some settings are configured in theconfig.php file located in the root directory:
Initial Setup Settings
These are used during installation:- initial_user: Default admin username (default: ‘admin’)
- initial_pass: Default admin password (default: ‘admin’)
- initial_email: Default admin email
- initial_empresa: Default company name (default: ‘E-’ + random number)
- initial_codpais: Default country code (default: ‘ESP’)
- lang: Default language code
User.php:284:
Plugin Control Settings
- disable_add_plugins: Disable plugin installation (checked in
Plugins.php:39) - disable_rm_plugins: Disable plugin removal (checked in
Plugins.php:312) - hidden_plugins: Comma-separated list of plugins to hide (checked in
Plugin.php:305)
Database Settings
- db_host: Database server hostname
- db_port: Database server port
- db_name: Database name
- db_user: Database username
- db_pass: Database password
- db_type: Database type (mysql, postgresql)
Settings Validation
The Settings model includes automatic HTML sanitization (Settings.php:99):
test() method also sanitizes the name:
Cache Management
Settings are cached for performance. Clear the cache when updating settings:Magic Methods
The Settings model implements magic methods for convenient property access:__get()
Access properties directly:Settings.php:50):
__set()
Set properties directly:Settings.php:81):
__isset()
Check if property exists:__unset()
Remove a property:JSON Storage Format
Settings properties are stored as JSON with flags (Settings.php:132):
- Unicode characters are stored properly
- Slashes are not escaped
- Human-readable format in database
Creating Custom Settings Groups
You can create your own settings groups for plugin or module configuration:Common Configuration Tasks
Change Default Warehouse
Change Default Company
Enable Beta Updates
Set Default Role for New Users
Settings vs Config
When to Use Settings (Database)
- User-configurable options
- Options that change during runtime
- Multi-company or multi-environment values
- Options that need UI for modification
When to Use Config (config.php)
- Installation/deployment settings
- Database connection details
- Security tokens and keys
- Environment-specific values
- Settings that shouldn’t change after deployment
Best Practices
- Group Related Settings: Use descriptive group names for organization
- Provide Defaults: Always provide sensible default values when accessing settings
- Clear Cache: Always clear cache after updating settings
- Validate Input: Validate and sanitize all setting values before saving
- Document Custom Settings: Document any custom settings groups you create
- Use Consistent Types: Keep property types consistent (don’t mix string/int/bool)
- Don’t Store Secrets: Avoid storing sensitive data in settings (use secure vaults)
Settings URL
The Settings model includes a custom URL method (Settings.php:159):
Related Files
- Settings Model:
/Core/Model/Settings.php - Tools Helper:
/Core/Tools.php - Configuration File:
/config.php(root directory) - User Model:
/Core/Model/User.php(uses settings) - Company Model:
/Core/Model/Empresa.php(uses settings) - Plugin Class:
/Core/Internal/Plugin.php(uses settings)

