The reset option works on a group basis. If the XML file references
groups that have already been created they will be replaced with the
fields in the new XML file unless the $reset parameter has been set
to false.
public loadFile ( string $file, boolean $reset = true, boolean $xpath = false ) : boolean | ||
$file | string | The filesystem path of an XML file. |
$reset | boolean | Flag to toggle whether form fields should be replaced if a field already exists with the same group/name. |
$xpath | boolean | An optional xpath to search for the fields. |
return | boolean | True on success, false otherwise. |
/** * Creates a new Form object * * @param string $name The name of the form. * @param string $source The form source filename without path and .xml extension e.g. "form.default" OR raw XML data * @param string $viewName The name of the view you're getting the form for. * @param array $options Options to the Form object * @param bool $replace Should form fields be replaced if a field already exists with the same group/name? * @param bool $xpath An optional xpath to search for the fields. * * @return Form|null The loaded form or null if the form filename doesn't exist * * @throws \RuntimeException If the form exists but cannot be loaded */ public function form($name, $source, $viewName, array $options = array(), $replace = true, $xpath = false) { // Get a new form instance $form = new Form($this->container, $name, $options); // If $source looks like raw XML data, parse it directly if (strpos($source, '<form') !== false) { if ($form->load($source, $replace, $xpath) === false) { throw new FormLoadData(); } return $form; } $formFileName = $this->getFormFilename($source, $viewName); if (empty($formFileName)) { if ($this->scaffolding) { $scaffolding = new ScaffoldingBuilder($this->container); $xml = $scaffolding->make($source, $viewName); if (!is_null($xml)) { return $this->form($name, $xml, $viewName, $options, $replace, $xpath); } } return null; } if ($form->loadFile($formFileName, $replace, $xpath) === false) { throw new FormLoadFile($source); } return $form; }