MetaModels\Helper\TableManipulation::checkColumnName PHP Метод

checkColumnName() публичный статический Метод

If there is any problem, an Exception is raised, stating the nature of the error in the Exception message.
public static checkColumnName ( string $strColName, boolean $blnAllowSystemCol = false ) : void
$strColName string The name of the column.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
Результат void
    public static function checkColumnName($strColName, $blnAllowSystemCol = false)
    {
        if (!self::isValidColumnName($strColName)) {
            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidColumnName'], $strColName));
        }
        if (!$blnAllowSystemCol && self::isSystemColumn($strColName)) {
            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['systemColumn'], $strColName));
        }
    }

Usage Example

Пример #1
0
 /**
  * Renames the underlying database structure for this field.
  *
  * @param string $strNewColumnName The new column name.
  *
  * @return void
  */
 public function renameColumn($strNewColumnName)
 {
     TableManipulation::checkColumnName($strNewColumnName);
     if ($this->getColName() && $this->getMetaModel()->getServiceContainer()->getDatabase()->fieldExists($this->getColName(), $this->getMetaModel()->getTableName(), true)) {
         TableManipulation::renameColumn($this->getMetaModel()->getTableName(), $this->getColName(), $strNewColumnName, $this->getSQLDataType());
     } else {
         $strBackupColName = $this->getColName();
         $this->set('colname', $strNewColumnName);
         $this->createColumn();
         $this->set('colname', $strBackupColName);
     }
 }