The FileEdit Class Hierarchy

Table of Contents


The FileEdit class hierarchie is responsible for the handling of the editing of files in the back-end. Its implementation makes heavy use of the template method pattern. The two main branches are TextFileEdit and ArrayFileEdit.


The predefined concrete subclasses of TextFileEdit offer a simple textarea to edit the content of a text file.


This branch offers editing of files storing data in an array structure. The predefined subclasses handle two- dimensional PHP arrays, which are used to store the configuration options and language strings of the core and plugins. The generated forms group the options in categories. The options can have the following types, which can be specified in a file metaconfig.php.

As of CMSimple_XH 1.7.0 it is also possible to mark configuration as advanced options by prepending a +, for instance +bool or +string. Such options are only displayed if the user presses the More … button in the configuration.


To display the edit form ::form() has to be called; to handle the form submission ::submit() has to be called. For instance:

require_once $pth['folder']['classes'] . 'FileEdit.php';
$editor = new XH_CoreConfigFileEdit();
if ($save) {
$o .= $editor->submit();
} else {
$o .= $editor->form();

By means of extending an appropriate class of the hierarchy, it is possible to make other files even in other formats editable online. An example:

require_once $pth['folder']['classes'] . 'FileEdit.php';
class MyTextFileEdit extends XH_TextFileEdit
function MyTextFileEdit()
$this->filename = 'path/of/the/file';
$this->params = array('what' => 'my_file', 'action' => 'save');
$this->redir = "?what=my_file&action=edit";
$this->textareaName = 'my_textarea';
if (isset($_REQUEST['what']) && $_REQUEST['what'] == 'my_file') {
$fileEditor = new MyTextFileEdit();
if ($_REQUEST['action'] == 'save') {
$o .= $fileEditor->submit();
} else {
$o .= $fileEditor->form();