Search code examples
phpyiiyii-extensionsyii-booster

YiiBooster. TbEditableColumn. Property "attribute" should be defined


I have a problem with TbEditedableColumn in YiiBooster 4.0.1

View:

$this->widget(
'application.extensions.booster.widgets.TbGridView',
array(
    'type' => 'striped bordered',
    'dataProvider' => new CActiveDataProvider('Stats'),
    'columns' => array(
        'pid',
        array(
            'class' => 'application.extensions.booster.widgets.TbEditableColumn',
            'name' => 'login',
            'sortable' => false,
            'editable' => array(
                //'model'  => $model,
                //'attribute' => 'login',
                'url' => $this->createUrl('stats/editableSaver'),
                'placement' => 'right',
                'inputclass' => 'span3'
            )
        )
    ),
)

);

Controller:

public function actionEditableSaver()
        {
            Yii::import('application.extensions.booster.components.TbEditableSaver');
            $es = new TbEditableSaver('Stats');
            $es->update();
        }

When I try to save the edited fields, I got this exception: Property "attribute" should be defined.

$es->attributes is empty.

How to fix that? Thanks.


Solution

  • From the source code, TbEditableSaver::update() obtains the attribute from a post or get parameter name:

    $this->attribute = yii::app()->request->getParam('name');
    $this->value = yii::app()->request->getParam('value');
    
    //checking params
    if (empty($this->attribute)) {
        throw new CException(Yii::t('TbEditableSaver.editable', 'Property "attribute" should be defined.'));
    }
    

    In order for this parameter to be sent in the update request it needs to be defined in the editable array. To fix this:

    'class' => 'application.extensions.booster.widgets.TbEditableColumn',
        'name' => 'login',
        'sortable' => false,
        'editable' => array(
            'name' => 'login',
            'url' => $this->createUrl('stats/editableSaver'),
            'placement' => 'right',
            'inputclass' => 'span3'
        )