yii\helpers\BaseHtml::getAttributeName PHP Méthode

getAttributeName() public static méthode

An attribute expression is an attribute name prefixed and/or suffixed with array indexes. It is mainly used in tabular data input and/or input of array type. Below are some examples: - [0]content is used in tabular data input to represent the "content" attribute for the first model in tabular input; - dates[0] represents the first array element of the "dates" attribute; - [0]dates[0] represents the first array element of the "dates" attribute for the first model in tabular input. If $attribute has neither prefix nor suffix, it will be returned back without change.
public static getAttributeName ( string $attribute ) : string
$attribute string the attribute name or expression
Résultat string the attribute name without prefix and suffix.
    public static function getAttributeName($attribute)
    {
        if (preg_match('/(^|.*\\])([\\w\\.]+)(\\[.*|$)/', $attribute, $matches)) {
            return $matches[2];
        } else {
            throw new InvalidParamException('Attribute name must contain word characters only.');
        }
    }

Usage Example

Exemple #1
0
 public function init()
 {
     parent::init();
     mt_srand((double) microtime() * 10000);
     $this->id = $this->id ? $this->id : 'files' . strtoupper(md5(uniqid(mt_rand(), true)));
     //var_dump($this->id);
     $this->name = isset($this->model) ? Html::getInputName($this->model, $this->attribute) : $this->id;
     if (isset($this->attribute)) {
         $this->pure_attribute = BaseHtml::getAttributeName($this->attribute);
     }
     if (!$this->file_id) {
         if (isset($this->attribute)) {
             $this->file_id = $this->model[$this->pure_attribute];
         } else {
             $this->file_id = -1;
         }
     }
     if (!$this->options) {
         $this->options = [];
     }
     if (!$this->select_callback) {
         $this->select_callback = false;
     }
     if (!$this->caption) {
         $this->caption = false;
     }
 }
All Usage Examples Of yii\helpers\BaseHtml::getAttributeName