Hello I am using tabular input to update a photos table:
http://www.yiiframework.com/doc-2.0/guide-input-tabular-input.html
The client validation work with default scenario, however I want write a rules to update scenario and this doesn’t work.
My controller:
<?php
public function actionActualiza()
{
$dataProvider= Fotos::find()->where(['foto_prov_id'=>$this->proveedor_id])
->indexBy('foto_id')->orderBy(['foto_orden'=>'ASC'])->all();
return $this->renderAjax('_actualizafotos', [
'dataProvider' => $dataProvider,
]);
}
?>
My view
<?php
$form = ActiveForm::begin([
'options' => [
'id' => 'actualiza-fotos-form'
]]);
foreach ($dataProvider as $key => $value) {
$title = $form->field($value, "[$key]foto_titulo")->textInput(['maxlength' => true])."<br />";
echo $title;
}
ActiveForm::end();
?>
My model
public function rules()
{
return [
[['eliminar_archivo','sort_list'], 'safe'],
[['foto_prov_id', 'foto_orden', 'foto_archivo'], 'required'],
['foto_titulo'], 'required', 'on'=>'update'],
[['foto_prov_id', 'foto_orden'], 'integer'],
[['foto_titulo', 'foto_descripcion', 'foto_archivo'], 'string', 'max' => 250],
[['foto_prov_id'], 'exist', 'skipOnError' => true, 'targetClass' => Proveedores::className(), 'targetAttribute' => ['foto_prov_id' => 'prov_id']],
];
}
Thank you very much