Hello. Passed many forums and articles, still nothing happens. There is a model
/** * @inheritdoc */ protected $mass; public static function tableName() { return 'TestRes2_general_inf'; } public function rules() { return [ [['id_TestRes1_all_types', 'Name'], 'required'], [['id_TestRes1_all_types'], 'integer'], [['Name'], 'string', 'max' => 150], [['id_TestRes1_all_types'], 'exist', 'skipOnError' => true, 'targetClass' => Testres1AllTypes::className(), 'targetAttribute' => ['id_TestRes1_all_types' => 'id']], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'id программного продукта', 'id_TestRes1_all_types'=>'id вид рез.тестирования', 'Name' => 'Название программного продукта', ]; } /** * @return \yii\db\ActiveQuery */ public function getParent() { return $this->hasOne(Testres1AllTypes::className(), ['id' => 'id_TestRes1_all_types']); } } Which works with the database and pulls information from there. There is a controller in which I send the model to the view.
class TestResultsController extends Controller { public function actionAntivirus() { $id = Yii::$app->getRequest()->getQueryParam('id'); $models = TestRes2GeneralInf::find()->where('id_TestRes1_all_types = :id', [':id' => $id])->all(); /*$searchModel = new Testres1AllTypesSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);*/ return $this->render('antivirus', [ // 'searchModel' => $searchModel, 'models' => $models, ]); } } So the whole problem in the submission. I need to implement these elements as checkboxList
<?php use yii\helpers\Html; use yii\grid\GridView; use yii\web\UrlManager; use yii\bootstrap\ActiveForm; use backend\models\TestRes2GeneralInf; use yii\base\Model; use yii\helpers\ArrayHelper; $this->title = 'Антивирусные программы1'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="site-contact"> <h1><?= Html::encode($this->title) ?></h1> <div class="row"> <div class="col-lg-5"> <?php $form = ActiveForm::begin([ 'id' => 'antivirus-test-results', 'action' => ['/test-results/antivirus-result'], 'options' => ['method' => 'post'] ]); ?> <?php $options = ArrayHelper::map($models, 'id', 'Name'); //Не знаю как правильно или так, echo $form->checkboxList($model,'mass',$options); //или так echo $form->field($models, 'mass')->checkboxList($options); ?> <div class="form-group"> <?= Html::submitButton('Результаты испытаний', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?> </div> <?php ActiveForm::end();?> </div> </div> After examining all the tips I learned that checkboxList returns a list of arrays and therefore in the model you need to add a property that will store an array of selected checkboxes. Because I changed the model
<?php namespace backend\models; use Yii; class TestRes2GeneralInf extends \yii\db\ActiveRecord {/ protected $mass; public static function tableName() { return 'TestRes2_general_inf'; } public function rules() { return [ [['id_TestRes1_all_types', 'Name'], 'required'], ['mass', 'safe'], [['id_TestRes1_all_types'], 'integer'], [['Name'], 'string', 'max' => 150], [['id_TestRes1_all_types'], 'exist', 'skipOnError' => true, 'targetClass' => Testres1AllTypes::className(), 'targetAttribute' => ['id_TestRes1_all_types' => 'id']], ]; } public function getMass() { return $this->mass; } public function setMass($value) { /** * Здесь в приватном свойстве mass после load будет хранится массив */ $this->mass = $value; } public function attributeLabels() { return [ 'id' => 'id программного продукта', 'id_TestRes1_all_types'=>'id вид рез.тестирования', 'Name' => 'Название программного продукта', ]; } public function getParent() { return $this->hasOne(Testres1AllTypes::className(), ['id' => 'id_TestRes1_all_types']); } } But he still writes a mistake. I do not understand what is wrong. In short, I need to get id-patches to be marked. I found an opportunity where he displays all the checkboxes that I need without errors in view-xy. But now the problem is when you click submit, it doesn’t send anything to my controller in this form
echo Html::checkboxList($check_values,[], ArrayHelper::map($models, 'Name', 'Name'), ['class' => 'checkbox']);
error_reporting(E_ALL); ini_set('display_errors', 'on');error_reporting(E_ALL); ini_set('display_errors', 'on');Then all errors will be displayed on the screen. - ilyaplot{/- ilyaplot