0
我嘗試沒有成功地從一個CGDYView的dropDownList更新數據庫。Yii從dropDownList更新數據庫
這裏是CGridView的代碼:)示範
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'invoice-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'username',
array(
'name' => 'state',
'type' => 'raw',
'value' => '$data->stateDropdown',
'filter' => array('0' => Yii::t('app', 'No'),
'1' => Yii::t('app', 'Yes'),
),
),
array(
'class' => 'CButtonColumn',
'template'=>'{view}',
),
),
)); ?>
下面是函數stateDropDown(的消氣:當我改變DROPDOWNLIST元件,所述
public function getStateDropdown()
{
$state = array(
0 => 'No',
1 => 'Yes',
);
return CHtml::dropDownlist('state', $this->state, $state, array(
'class' => 'state',
'data-id' => $this->id,
'onchange' => 'alert(0);',
));
}
警告腳本被觸發,但是當我嘗試使用一個函數時,我有一個錯誤。我想使用下面描述的這個函數來更新數據庫中的狀態值。
function updateState($state, $id)
{
$user = User::model()->findByPk($id);
$user->state = $state;
$user->update();
}
我如何能真正調用函數updateState()代替警報(0)
爲什麼你指的是yii2標籤,而你的代碼看起來像Yii1? – scaisEdge
@scaisEdge yii1或yii2解決方案將幫助我。也許有人可以有一個yii2解決方案來解決我的問題。 – stfsngue
你不能像這樣更新數據庫,至多你可以使用網格過濾數據庫,如果是的話,你也做錯了 – tinybyte