T
T
The Dragger2015-05-11 14:57:16
Yii
The Dragger, 2015-05-11 14:57:16

Undefined index, how to fix the error?

hello guys!!!

$positions =[
  1=>Yii::t('Ui','Председатель махала'),
  2=>Yii::t('Ui','Секретарь'),
  3=>Yii::t('Ui','Советник'),
  4=>Yii::t('Ui','Участковый')];
?>
</div><!-- search-form -->
<?php $this->widget('bootstrap.widgets.TbGridView',array(
  'id'=>'ref-employees-mahala-grid	',
  'dataProvider'=>$model->search(),
  'filter'=>$model,
  'columns'=>array(
    'id',
    array('name'=>'mahala_id', 'value'=>'$data->mahala->name_ru'),
    array('name' => 'position_type','value'=> $positions[$model->position_type]),
    'full_name_ru',
    'full_name_uz',
    'full_name_en',
    array(
      'class'=>'bootstrap.widgets.TbButtonColumn',
    ),
  ),
)); ?>

in $model->position_type numbers 1,2,4 are stored
In other vishka all the rules work here, it's not clear why?
Mistake
Undefined index:

/var/www/alex/admin/protected/views/refEmployeesMahala/admin.php(53)

41     2=>Yii::t('Ui','Секретарь'),
42     3=>Yii::t('Ui','Советник'),
43     4=>Yii::t('Ui','Участковый')];
44 ?>
45 </div><!-- search-form -->
46 <?php $this->widget('bootstrap.widgets.TbGridView',array(
47     'id'=>'ref-employees-mahala-grid    ',
48     'dataProvider'=>$model->search(),
49     'filter'=>$model,
50     'columns'=>array(
51         'id',
52         array('name'=>'mahala_id', 'value'=>'$data->mahala->name_ru'),
53         array('name' => 'position_type','value'=> $positions[$model->position_type]),
54         'full_name_ru',
55         'full_name_uz',
56         'full_name_en',
57         array(
58             'class'=>'bootstrap.widgets.TbButtonColumn',
59         ),
60     ),
61 )); ?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Papa, 2015-05-11
Stifflera @PapaStifflera

Because the value on line 53 is incorrect. For an example, you can look at line 52 and the documentation.

M
Maxim Grechushnikov, 2015-05-11
@maxyc_webber

or $model->position_type is empty or there is zero or more 4

P
pantsarny, 2015-05-13
@pantsarny

you have $model - an object for the filter, inside TbGridView in iteration the current object is available by the $data variable.

function getPosition(id)
{
 $positions = [
  1=>Yii::t('Ui','Председатель махала'),
  2=>Yii::t('Ui','Секретарь'),
  3=>Yii::t('Ui','Советник'),
  4=>Yii::t('Ui','Участковый')];
  return $positions[id];
}

53:
For good, this function should be a method of the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question