public function createFormForModel(string $classname, DAO $dao)
    {
        if (!is_a($classname, Model::class, true))
            throw new \InvalidArgumentException("Not a valid Model class provided");

        $form = new Form($classname);
        $refl = new ReflectionClass($classname);
        $fields = $this->getAnnotatedFields($refl, []);

        $columns = $dao->getColumns();
        foreach ($columns as $name => $coldef)
        {
            if (isset($fields[$name]))
                continue;

            // Ignore serial columns
            if ($coldef->getSerial())
                continue;

            $validator = function ($value) use ($classname, $coldef)
            {
                return $classname::validate($coldef, $value);
            };

            $type = new Validator(Type::VALIDATE_CUSTOM, ['custom' => $validator]);
            $field = new FormField($name, $type, 'text', null); 

            $fields[$name] = $field;
        }

        foreach ($fields as $name => $field)
            $form->add($field);

        $this->addFormValidators($refl, [], $form);
        return $form;
    }
public function createFormForModel(string $classname, DAO $dao)
    {
        if (!is_a($classname, Model::class, true))
            throw new \InvalidArgumentException("Not a valid Model class provided");

        $form = new Form($classname);
        $refl = new ReflectionClass($classname);
        $fields = $this->getAnnotatedFields($refl, []);

        $columns = $dao->getColumns();
        foreach ($columns as $name => $coldef)
        {
            if (isset($fields[$name]))
                continue;

            // Ignore serial columns
            if ($coldef->getSerial())
                continue;

            $validator = function ($value) use ($classname, $coldef)
            {
                return $classname::validate($coldef, $value);
            };

            $type = new Validator(Type::VALIDATE_CUSTOM, ['custom' => $validator]);
            $field = new FormField($name, $type, 'text', null); 

            $fields[$name] = $field;
        }

        foreach ($fields as $name => $field)
            $form->add($field);

        $this->addFormValidators($refl, [], $form);
        return $form;
    }
public function createFormForModel ( string $ classname , DAO $ dao ) { if ( ! is_a ( $ classname , Model :: class , true ) ) throw new \ InvalidArgumentException ( "Not a valid Model class provided" ) ; $ form = new Form ( $ classname ) ; $ refl = new ReflectionClass ( $ classname ) ; $ fields = $ this -> getAnnotatedFields ( $ refl , [ ] ) ; $ columns = $ dao -> getColumns ( ) ; foreach ( $ columns as $ name => $ coldef ) { if ( isset ( $ fields [ $ name ] ) ) continue ; // Ignore serial columns if ( $ coldef -> getSerial ( ) ) continue ; $ validator = function ( $ value ) use ( $ classname , $ coldef ) { return $ classname :: validate ( $ coldef , $ value ) ; } ; $ type = new Validator ( Type :: VALIDATE_CUSTOM , [ 'custom' => $ validator ] ) ; $ field = new FormField ( $ name , $ type , 'text' , null ) ; $ fields [ $ name ] = $ field ; } foreach ( $ fields as $ name => $ field ) $ form -> add ( $ field ) ; $ this -> addFormValidators ( $ refl , [ ] , $ form ) ; return $ form ; }
Create a form based on a database model

@param string $classname The name of the Model class
@param DAO $dao The DAO that provides more information about the class
Create a form based on a database model