Example #1
0
 /**
  * Form constructor. Build form based on model properties
  * @param Model $model
  * @param array|null $property
  * @param array|null $layerFiles
  * @throws SyntaxException
  */
 public function __construct($model, array $property = null, array $layerFiles = null)
 {
     // prevent white-screen locks when model is not passed or passed wrong
     if (!$model instanceof Model) {
         throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()');
     }
     $this->model = $model;
     $this->name = $model->getFormName();
     // check if passed custom layer file
     if (Obj::isArray($layerFiles) && count($layerFiles) > 0) {
         foreach (array_keys(static::$structLayer) as $type) {
             if (isset($layerFiles[$type]) && Obj::isString($layerFiles[$type])) {
                 static::$structLayer[$type] = $layerFiles[$type];
             }
         }
     }
     // set model submit method
     $property['method'] = $this->model->getSubmitMethod();
     $property['id'] = $this->name;
     // define form id
     // if action is not defined - define it
     if (Str::likeEmpty($property['action'])) {
         $property['action'] = App::$Request->getFullUrl();
     }
     // set property global for this form
     $this->formProperty = $property;
 }