V
V
Vyacheslav_Shilov2020-08-03 15:50:45
Yii
Vyacheslav_Shilov, 2020-08-03 15:50:45

How to update all rows by attributes in Yii1.1?

Please tell me how to implement correctly. I have a model, I rake out all the lines from it by the 'phone = 1' attribute.
Now I want to display all these 'phone' inputs in the view in a column, with the ability to change them. I am doing like this
Controller Action:

<?php
class HomeController extends Controller
{
  public function actionIndex()
  {    
        $model = Post1::model()->findAllByAttributes(array('phone' => array(1)));

        $this->render('index', array(
            'model'=>$model,
        ));
}

View:
<?php
/* @var $this HomeController */

?>
<?php $form = $this->beginWidget('CActiveForm', array(
    'id'=>'user-form',
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'focus'=>array($model,'firstName'),
)); ?>

<?php echo $form->errorSummary($model); ?>
    <?php foreach ($model as $one){?>
    <div class="row">
        <?php echo $form->labelEx($one,'name'); ?>
        <?php echo $form->textField($one,'name'); ?>
        <?php echo $form->error($one,'name'); ?>
    <?php }?>
  
    <div class="row buttons">
        <?php echo CHtml::submitButton('Сохранить'); ?>
    </div>

<?php $this->endWidget(); ?>

Not sure how to save them. In short, what's the best way to do it?
The problem is that in labelEx it doesn't allow you to write "$model" as it is done with a one-dimensional array.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question