getAttributeName() public static method

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
return string the attribute name without prefix and suffix.
Beispiel #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;
     }
 }
Beispiel #2
0
 public function init()
 {
     parent::init();
     if (!$this->params) {
         $this->params = ['id' => 'files' . time() . rand(1, 100)];
     } else {
         $this->params = $this->params;
     }
     $sql = 'select * from fajl where vladelec = :user_id';
     $polzovatel_id = ApiGlobals::getPolzovatelId();
     if (isset($this->attribute)) {
         $pureAttrbiute = BaseHtml::getAttributeName($this->attribute);
         $this->params['pureAttribute'] = $pureAttrbiute;
     }
     if (!$polzovatel_id) {
         throw new \Exception();
     }
     if ($res = \Yii::$app->db->createCommand($sql)->bindValue(':user_id', $polzovatel_id)->queryAll()) {
         $files = array();
         foreach ($res as $k => $v) {
             $files[$v['id']] = $v;
         }
         $this->params['files'] = $files;
     } else {
         $this->params['files'] = array();
     }
     if (isset($pureAttrbiute) && isset($this->model[$pureAttrbiute]) && $this->model[$pureAttrbiute] && $this->params['files'][$this->model[$pureAttrbiute]]['vneshnee_imya_fajla']) {
         $this->params['btn-text'] = $this->params['files'][$this->model[$pureAttrbiute]]['vneshnee_imya_fajla'];
     }
     if (!isset($this->params['btn-text'])) {
         $this->params['btn-text'] = 'Выбрать файл';
     }
     $this->params['name'] = isset($this->model) ? Html::getInputName($this->model, $this->attribute) : $this->params['id'];
     //if (!isset($this->params['selected'])) $this->params['selected'] = null;
     //else $this->params['btn-text'] = $this->params['files'][$this->params['selected']]
     //var_dump($this->params['files']);
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         if ($this->enableLabel === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel}'])) {
             $this->renderLabelParts();
         }
         if ($this->enableError === false || !$this->model->getFirstError(BaseHtml::getAttributeName($this->attribute))) {
             $this->parts['{error}'] = '';
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
         }
     }
     return parent::render($content);
 }
Beispiel #4
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\MaskedInput;
use yii\helpers\BaseHtml;
/* @var $this yii\web\View */
/* @var $model app\models\Fornecedor */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="fornecedor-form">

	<?php $form = ActiveForm::begin(); ?>
	<?= Html::activeLabel($model, BaseHtml::getAttributeName('cnpj')) ?>
	<?php // $form->field($model, 'cnpj')->textInput();

	echo MaskedInput::widget([
		'model'=>$model,
		
		'attribute' => 'cnpj',
		'mask'=>'99.999.999/9999-99',
		]);

		?>

		<?= $form->field($model, 'nome')->textInput(['maxlength' => true]) ?>

		<?= $form->field($model, 'endereco')->textInput(['maxlength' => true]) ?>

		<div class="form-group">