form -> model > array

Hi developers :)

I have dynamic form

and I want show values in form





$sql = $connection->createCommand('select candidad, ...');

		

$result = $sql -> queryAll();

$count = 1;


foreach($result as $row ) {


   $model['candidad_array[' .$count . ']'] = $row["candidad"];

   <?= $form->field($model, 'candidad_array[' .$count . ']'])->textInput() ?>

   ...

   $count = $count + 1;

}




in models I declare


class FormX extends \yii\db\ActiveRecord

{

    /**

     * @inheritdoc

     */

    

    public $candidad_array = array();

    ...




I have error


Setting unknown property: app\models\FormX::candidad_array[1]

Please post full error message along with file name and trace.

I changed code to:





    foreach($result as $i=>$item) {

        echo $form->field($item,"[$i]candidad"); 

    }




and I have error


Call to a member function formName() on array

from


 in C:\xampp\htdocs\yii2_tools\vendor\yiisoft\yii2\helpers\BaseHtml.php at line 2096

2087208820892090209120922093209420952096209720982099210021012102210321042105     * See [[getAttributeName()]] for explanation of attribute expression.

     *

     * @param Model $model the model object

     * @param string $attribute the attribute name or expression

     * @return string the generated input name

     * @throws InvalidParamException if the attribute name contains non-word characters.

     */

    public static function getInputName($model, $attribute)

    {

        $formName = $model->formName();

        if (!preg_match('/(^|.*\])([\w\.]+)(\[.*|$)/', $attribute, $matches)) {

            throw new InvalidParamException('Attribute name must contain word characters only.');

        }

        $prefix = $matches[1];

        $attribute = $matches[2];

        $suffix = $matches[3];

        if ($formName === '' && $prefix === '') {

            return $attribute . $suffix;

        } elseif ($formName !== '') {

2. yii\base\ErrorHandler::handleFatalError()

problem is in this line -> $formName = $model->formName();

I think $result = $sql -> queryAll(); not give all params like $result = app\models\FormX::find()->all(); because for $result = app\models\FormX::find()->all(); work perfect.

Yes, query builder isn’t creating models for you.