### Basic FOF Joomla! Installation Script Structure Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Provides the fundamental structure for a Joomla! installation script that extends FOF's InstallScript class. It includes necessary checks for FOF inclusion and defines component-specific properties. ```php +-- backend Component files under site's "administrator" directory +-- frontend Component files under site's root director +-- media OPTIONAL. Component media files, under site's "media" directory +-- cli OPTIONAL. Component CLI script installed under site's "cli" directory +-- language OPTIONAL. Language files for your component. ``` -------------------------------- ### FOF Joomla! Installation Script Component Properties Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Defines essential properties for the FOF installation script, specifying the component's internal name and its human-readable title. These are used by the FOF framework for registration and management. ```php { protected $componentName = 'com_foobar'; protected $componentTitle = 'Foobar Component'; } ``` -------------------------------- ### Joomla! Manifest Script File Declaration Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Declares the installation script file within the Joomla! component's XML manifest. This line specifies the name and location of the script file that Joomla! will execute during installation or uninstallation. ```xml script.com_foobar.php ``` -------------------------------- ### FOF Library Inclusion Check Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Checks if the FOF 3.0 library is already included and attempts to load it if not. This is crucial as the installation script relies on FOF's functionality. ```php // Load FOF if not already loaded if (!defined('FOF30_INCLUDED') && !@include_once(JPATH_LIBRARIES . '/fof30/include.php')) { throw new RuntimeException('This component requires FOF 3.0.'); } ``` -------------------------------- ### Configuration File Setup Source: https://github.com/akeeba/fof/blob/development/Tests/README.md Copy the distribution configuration file to a new file and update its contents to point to your local testing environment, such as database credentials and site root. ```bash cp Tests/config.dist.php Tests/config.php ``` -------------------------------- ### FOF 3 Component Structure Setup Source: https://github.com/akeeba/fof/wiki/Migrating-components-from-FOF-2-to-FOF-3 Initial steps for setting up a new FOF 3 component, including the manifest file and basic component structure. This involves defining namespaces and factory configurations. ```xml YourComponentName 1.0.0 MyCompany\MyApp ``` ```php // myapp.php (main entry point) require_once 'path/to/fof/autoload.php'; $app = FOF3\Application::getInstance(); $app->dispatch(); ``` -------------------------------- ### FOF Database Installer Class Constructor Source: https://github.com/akeeba/fof/wiki/The XML Database Schema Installer Initializes the FOF Database Installer class. It requires a database object and the directory path to the XML schema files. The directory parameter can be overridden from the default 'sql/xml'. ```apidoc FOF30\Database\Installer(db, directory) - db: The database object used to execute SQL commands. Use JFactory::getDbo() if unsure. - directory: The absolute filesystem path where the XML schema files are located. Defaults to 'sql/xml'. ``` -------------------------------- ### FOF Joomla! Installation Script Class Naming Convention Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Illustrates the strict naming convention required for Joomla! installation scripts that extend FOF's InstallScript. The class name must follow the pattern 'Com_ComponentNameInstallerScript' with precise capitalization. ```php class Com_FoobarInstallerScript extends \FOF30\Utils\InstallScript ``` -------------------------------- ### FOF Database Installer Methods Source: https://github.com/akeeba/fof/wiki/The XML Database Schema Installer Provides methods to manage database schemas. `updateSchema()` creates or updates tables, and `removeSchema()` drops tables. These methods are crucial for component installation, updates, and uninstallation. ```apidoc public function updateSchema() - Description: Creates or updates the tables of your component in the database. - Usage: Recommended to call in installation scripts and the main back-end page of your component to handle updates even without re-installation. - Behavior: Executes SQL commands based on table/field existence or custom SQL queries defined in XML schema files. public function removeSchema() - Description: Removes (drops) the tables of your component. - Usage: Recommended only for the uninstallation script of your component. - Warning: Permanently removes all database tables defined in the XML schema file without further warning. ``` -------------------------------- ### Composer Dependency Management Source: https://github.com/akeeba/fof/blob/development/Tests/README.md Install project dependencies using Composer. If you need to update the dependencies to their latest versions, use the update command. ```composer composer install ``` ```composer composer update ``` -------------------------------- ### Model Header Field Configuration Example Source: https://github.com/akeeba/fof/wiki/Model-Header Illustrates the structure and attributes for configuring a Model Header field. This example shows how to specify the data model, key and value fields, translation, access control, placeholder text, and state-based filtering. ```XML
1
``` -------------------------------- ### Joomla! Direct Access Prevention Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Standard Joomla! code snippet to prevent direct access to the script file. This ensures the script can only be executed within the Joomla! environment. ```php // no direct access defined('_JEXEC') or die; ``` -------------------------------- ### PHP: Specify Files/Folders to Remove from All Versions Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Specifies files and folders to be removed from both free and paid versions of an extension. This is useful for refactoring code and cleaning up obsolete files. Paths are relative to the site's root. ```php protected $removeFilesAllVersions = array( 'files' => array( 'administrator/components/com_foobar/helpers/old_helper.php' ), 'folders' => array( 'administrator/components/com_foobar/old_feature' ) ); ``` -------------------------------- ### Example SQL Query within Action Source: https://github.com/akeeba/fof/wiki/The XML Database Schema Installer Shows an SQL INSERT statement executed as part of an action when its conditions are met. ```SQL INSERT IGNORE INTO `#__admintools_profiles` (`id`,`description`, `configuration`, `filters`) VALUES (1,'Default PHP Change Scanner Profile','',''); ``` -------------------------------- ### Example Action with Conditional Insert Source: https://github.com/akeeba/fof/wiki/The XML Database Schema Installer This example demonstrates an action that inserts a default profile if a specific record does not exist. It uses an 'equals' condition with a 'not' operator to check the count of existing records. ```APIDOC ``` -------------------------------- ### PHP: Specify Files/Folders to Remove from Free Version Source: https://github.com/akeeba/fof/wiki/The-InstallScript-class Specifies files and folders to be removed exclusively from the free version of an extension. This is typically used when migrating features to a paid version. Paths are relative to the site's root. ```php protected $removeFilesFree = array( 'files' => array( 'administrator/components/com_foobar/helpers/whatever.php' ), 'folders' => array( 'administrator/components/com_foobar/baz' ) ); ``` -------------------------------- ### Example SQL Query within Condition Source: https://github.com/akeeba/fof/wiki/The XML Database Schema Installer Illustrates a SQL query used within an `` tag to check for the existence of a record. ```SQL SELECT COUNT(*) FROM `#__admintools_profiles` WHERE `id` = 1; ``` -------------------------------- ### Default MVC Class Extension Example Source: https://github.com/akeeba/fof/wiki/The-Factory Demonstrates how to extend a default MVC class provided by FOF when using the MagicSwitchFactory. This ensures your custom classes inherit the necessary base functionality. ```php class Items extends DefaultDataModel { // .... } ``` -------------------------------- ### Enable FOF Scaffolding via Container Initialization Source: https://github.com/akeeba/fof/wiki/Scaffolding Demonstrates how to enable the FOF Scaffolding feature and its auto-save functionality by passing parameters during the container instantiation. This is the primary method for enabling scaffolding when a component starts. ```php $container = FOF30\Container\Container::getInstance('com_example', array( 'scaffolding' => true, 'saveScaffolding' => true, ))->dispatcher->dispatch(); ``` -------------------------------- ### Instantiate and Configure Download Helper (PHP) Source: https://github.com/akeeba/fof/wiki/The Download Helper Demonstrates how to create an instance of the FOF30\Download\Download helper class, passing the component's container. It also shows how to retrieve the active adapter name and configure adapter-specific options. ```php $download = new FOF30\Download\Download($container); $adapter = $download->getAdapterName(); $download->setAdapterOptions([ CURLOPT_FOLLOWLOCATION => 0, CURLOPT_USERAGENT => 'AcmeExample/1.0', ]); ``` -------------------------------- ### Get Current Extension Version Source: https://github.com/akeeba/fof/wiki/The Update package Demonstrates how to fetch the currently installed version of the extension using the getVersion() method. This is useful for comparing against available updates. ```php $currentVersion = $container->model('MyUpdates')->getVersion(); ``` -------------------------------- ### Get Root Node using TreeModel in PHP Source: https://github.com/akeeba/fof/wiki/The TreeModel Retrieves the root node of the hierarchical data structure managed by FOF's TreeModel. This is the starting point for navigating the tree. ```php $rootNode = $model->getRoot(); ``` -------------------------------- ### Initialize Chunked Download with importFromURL in PHP Source: https://github.com/akeeba/fof/wiki/The Download Helper This snippet demonstrates the initial setup for a chunked download using the importFromURL method. It outlines the essential configuration options required to specify the remote URL, local file path, chunk size, and execution time limits for the download process. ```php $options = [ // Setup 'url' => 'http://www.example.com/big.zip', 'localFilename' => JPATH_SITE . '/tmp/big.zip', 'maxExecTime' => 5, 'runTimeBias' => 75, 'length' => 1048576, // Runtime 'frag' => -1, 'totalSize' => -1, 'doneSize' => -1, ]; $response = $download->importFromURL($options); ``` -------------------------------- ### FOF 3 Component Entry Point Source: https://github.com/akeeba/fof/wiki/Getting-started-with-a-FOF-component This PHP script serves as the entry point for a FOF 3 component. It ensures FOF 3.0 is included, retrieves a component-specific container instance, and dispatches the component's execution. It's crucial to omit the closing PHP tag to prevent potential session issues. ```php dispatcher->dispatch(); ``` -------------------------------- ### Configure Update Site and Extra Query Source: https://github.com/akeeba/fof/wiki/The Update package Provides an example of setting multiple configuration parameters in the constructor, including the update site URL, site name, and an extra query string for authentication or specific parameters. ```php class MyUpdates extends FOF30\Update\Update { public function __construct($config = array()) { $config['update_component'] = 'com_foobar'; $config['update_sitename'] = 'Foobar updates'; $config['update_site'] = 'http://www.example.com/updates/com_foobar.xml'; $config['update_extraquery'] = 'authorisation=mySuperSecretCode'; parent::__construct($config); } } // Parameter descriptions: // - update_sitename: Name of the update site. // - update_site: URL to the update XML file. // - update_extraquery: Appended to download URLs for authentication or custom parameters. ``` -------------------------------- ### FOF Behavior Class Naming Convention Example Source: https://github.com/akeeba/fof/wiki/Model-behaviors Provides an example of how FOF determines the class name for a behavior, illustrating the search order for custom and framework-provided behaviors. ```php /* * For component com_example, namespace Acme\Example\Admin, Items model, Filters behavior: * FOF will look for: * 1. Acme\Example\Admin\Model\Behaviour\Items\Filters * 2. Acme\Example\Admin\Model\Behaviour\Filters * 3. FOF30\Model\DataModel\Behaviour\Filters */ FOF30\Container\Container::getInstance('com_example') ->factory->model('Items', array('behaviours' => array('Filters')))-> ``` -------------------------------- ### Example `fof.xml` Configuration Source: https://github.com/akeeba/fof/wiki/The-XML-configuration-file This snippet demonstrates the typical structure of a `fof.xml` file used for configuring FOF components. It includes sections for common settings like container, dispatcher, authentication, model definitions with relations and behaviors, and view-specific configurations for task mapping, ACL, and toolbars. ```xml published foo,bar,baz browse core.manage