-
Notifications
You must be signed in to change notification settings - Fork 0
Scaffolding
The scaffolding feature has been depreciated since FOF v3.6
One of the main problems creating a new FOF component or a new view in an existing FOF component is the need to enter sample data and create a quick prototype of the view and then continue working from there. Since FOF 2.0 you'd have to at least create two XML form files, one for the browse view and one for the add/edit view. This makes the initial learning curve a bit steep, as you need to understand how forms work before being able to play with FOF.
The Scaffolding feature added in FOF 3 addresses this issue. When enabled FOF looks at your model and finds the database table fields and their types. Based on this information it can create an automatic XML form definition and register any missing language strings based on some conventions. The views won't win any design contest or even be a very good or logical fit to a user interface but they do provide a good starting point.
Moreover, the Scaffolding results –the XML view files and language strings created on the fly– can be optionally saved to disk. This lets you design the database structure, enable scaffolding and automatic saving and presto! FOF will have created a set of XML forms and a language file you can start working with.
In order to use Scaffolding you need to set two container parameters:
- scaffolding (default: false) Set to true to enable the Scaffolding feature. If a view template is not found for the view you're trying to access FOF will create one automatically
- saveScaffolding (default: false) Set to true to have FOF save the Scaffolding-generated XML form and language strings to the disk. Please remember that as soon as these files are written FOF will no longer create automatic XML forms through Scaffolding since a view template will now be found.
For example, the code in your component's entry point file could look like this:
$container = FOF30\Container\Container::getInstance('com_example', array(
'scaffolding' => true,
'saveScaffolding' => true,
))->dispatcher->dispatch();
Scaffolding is a very neat feature and you might be tempted to use it in production. DON'T DO THAT! Scaffolding is designed as a method for quick prototyping in development environments. It is NOT designed to be used in production environments. When Scaffolding is enabled any access to a view without a corresponding view template will result in an automatic XML form being generated. Since this view contains all fields in your database table except for the created, modified and locked fields it could be a security or privacy issue. This is why you need to enable it explicitly through code and not with a request parameter.
Moreover be very careful when using the automatic save feature. Scaffolding's auto-save will save both the XML form file and the component's language INI file. The latter means that any comments you have put in your language INI file will disappear.
The container options only have an effect when the Factory object is first created by the Container. Changing them at any later point in time will have no effect. There is, however, a way to manipulate the Scaffolding feature after the Factory object has been created.
You can enable Scaffolding at any time with:
$container->factory->setScaffolding(true);
Likewise, you can enable the Scaffolding auto-save feature with:
$container->factory->setSaveScaffolding(true);
The best place to do that would be your Controller's constructor or execute()
method, i.e. before the Controller asks the Model if there is an XML form available. Scaffolding is implemented in the Factory's form()
method which checks the availability of an XML form file and instantiates it on behalf of the Model.
FOF (Framework on Framework) and its documentation are Copyright © 2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd.
FOF is Open Source Software, distributed under the GNU General Public License, version 2 of the license, or (at your option) any later version.
The FOF Wiki content is provided under the GNU Free Documentation License, version 1.3 of the license, or (at your option) any later version.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found on the GNU site.