src/Common/Model/Base.php
public function describeFields($sTable = null)
    {
        $sTable  = $sTable ?: $this->getTableName();
        $oDb     = Factory::service('Database');
        $aResult = $oDb->query('DESCRIBE `' . $sTable . '`;')->result();
        $aFields = [];

        if (classUses($this, Localised::class)) {

            /** @var Locale $oLocale */
            $oLocale           = Factory::service('Locale');
            $aSupportedLocales = $oLocale->getSupportedLocales();
            $aOptions          = array_combine(
                $aSupportedLocales,
                array_map(function (\Nails\Common\Factory\Locale $oLocale) {
                    return $oLocale->getDisplayLanguage();
                }, $aSupportedLocales)
            );

            $aFields[] = (object) [
                'key'        => 'locale',
                'label'      => 'Locale',
                'type'       => 'dropdown',
                'allow_null' => false,
                'validation' => ['required', 'supportedLocale'],
                'options'    => $aOptions,
                'class'      => 'select2',
                'info'       => 'This field specifies what language the item is written in.',
                'default'    => $oLocale->getDefautLocale(),
            ];
        }

        foreach ($aResult as $oField) {

            $oTemp = (object) [
                'key'        => $oField->Field,
                'label'      => $this->describeFieldsPrepareLabel($oField->Field),
                'type'       => null,
                'allow_null' => $oField->Null === 'YES',
                'validation' => [],
                'default'    => null,
            ];

            //  Guess the field's type and some basic validation
            $this->describeFieldsGuessType($oTemp, $oField->Type);
            $this->describeFieldsGuessValidation($oTemp, $oField->Type);

            $aFields[$oTemp->key] = $oTemp;
        }

        if (classUses($this, Localised::class)) {
            unset($aFields['language']);
            unset($aFields['region']);
        }

        return $aFields;
    }
public function describeFields($sTable = null)
    {
        $sTable  = $sTable ?: $this->getTableName();
        $oDb     = Factory::service('Database');
        $aResult = $oDb->query('DESCRIBE `' . $sTable . '`;')->result();
        $aFields = [];

        if (classUses($this, Localised::class)) {

            /** @var Locale $oLocale */
            $oLocale           = Factory::service('Locale');
            $aSupportedLocales = $oLocale->getSupportedLocales();
            $aOptions          = array_combine(
                $aSupportedLocales,
                array_map(function (\Nails\Common\Factory\Locale $oLocale) {
                    return $oLocale->getDisplayLanguage();
                }, $aSupportedLocales)
            );

            $aFields[] = (object) [
                'key'        => 'locale',
                'label'      => 'Locale',
                'type'       => 'dropdown',
                'allow_null' => false,
                'validation' => ['required', 'supportedLocale'],
                'options'    => $aOptions,
                'class'      => 'select2',
                'info'       => 'This field specifies what language the item is written in.',
                'default'    => $oLocale->getDefautLocale(),
            ];
        }

        foreach ($aResult as $oField) {

            $oTemp = (object) [
                'key'        => $oField->Field,
                'label'      => $this->describeFieldsPrepareLabel($oField->Field),
                'type'       => null,
                'allow_null' => $oField->Null === 'YES',
                'validation' => [],
                'default'    => null,
            ];

            //  Guess the field's type and some basic validation
            $this->describeFieldsGuessType($oTemp, $oField->Type);
            $this->describeFieldsGuessValidation($oTemp, $oField->Type);

            $aFields[$oTemp->key] = $oTemp;
        }

        if (classUses($this, Localised::class)) {
            unset($aFields['language']);
            unset($aFields['region']);
        }

        return $aFields;
    }
public function describeFields ( $ sTable = null ) { $ sTable = $ sTable ? : $ this -> getTableName ( ) ; $ oDb = Factory :: service ( 'Database' ) ; $ aResult = $ oDb -> query ( 'DESCRIBE `' . $ sTable . '`;' ) -> result ( ) ; $ aFields = [ ] ; if ( classUses ( $ this , Localised :: class ) ) { /** @var Locale $oLocale */ $ oLocale = Factory :: service ( 'Locale' ) ; $ aSupportedLocales = $ oLocale -> getSupportedLocales ( ) ; $ aOptions = array_combine ( $ aSupportedLocales , array_map ( function ( \ Nails \ Common \ Factory \ Locale $ oLocale ) { return $ oLocale -> getDisplayLanguage ( ) ; } , $ aSupportedLocales ) ) ; $ aFields [ ] = ( object ) [ 'key' => 'locale' , 'label' => 'Locale' , 'type' => 'dropdown' , 'allow_null' => false , 'validation' => [ 'required' , 'supportedLocale' ] , 'options' => $ aOptions , 'class' => 'select2' , 'info' => 'This field specifies what language the item is written in.' , 'default' => $ oLocale -> getDefautLocale ( ) , ] ; } foreach ( $ aResult as $ oField ) { $ oTemp = ( object ) [ 'key' => $ oField -> Field , 'label' => $ this -> describeFieldsPrepareLabel ( $ oField -> Field ) , 'type' => null , 'allow_null' => $ oField -> Null === 'YES' , 'validation' => [ ] , 'default' => null , ] ; //  Guess the field's type and some basic validation $ this -> describeFieldsGuessType ( $ oTemp , $ oField -> Type ) ; $ this -> describeFieldsGuessValidation ( $ oTemp , $ oField -> Type ) ; $ aFields [ $ oTemp -> key ] = $ oTemp ; } if ( classUses ( $ this , Localised :: class ) ) { unset ( $ aFields [ 'language' ] ) ; unset ( $ aFields [ 'region' ] ) ; } return $ aFields ; }
Describes the fields for this model automatically and with some guesswork;
for more fine grained control models should overload this method.

@param string|null $sTable The database table to query

@return array
Describes the fields for this model automatically and with some guesswork ; for more fine grained control models should overload this method .