tokiyashi
tokiyashi

Reputation: 85

Setting array inputs rules - Yii Framework

I'm learning yii framework for an e-commerce project and it was going great so far. I have an addition form for estates and that form is generating using database. The code below, generates the form (/views/ad/_form), and giving names to input fields like detail["ad-title"], detail["ad-image"] etc.

    <?php 
    $connection = Yii::app()->db;
    $command = $connection->createCommand("SELECT * FROM eml_ozellikler");
    $options = $command->queryAll();
    $command = $connection->createCommand("SELECT * FROM eml_kurallar");
    $rules = $command->queryAll();
    $i = 0;
    foreach($options as $option){
        echo '<div class="row">';
        echo $form->labelEx($model, 'detail["'.$option['name'].'"]');
        switch($option['tur']){
            case "textfield":
                echo $form->textField($model, 'detail["'.$option['name'].'"]');
                break;
            case "textarea":
                echo $form->textArea($model, 'detail["'.$option['name'].'"]', array('rows'=>'5','cols'=>'40'));
                break;
            case "integer":
                echo $form->textField($model, 'detail["'.$option['name'].'"]');
                break;
            case "selectbox":
                CHtml::dropDownList($option['label'], 'detail["'.$option['name'].'"]', $rules[$i]['values']);
                break;
            case "radio":
                break;
            case "file":
                echo $form->fileField($model, 'detail["'.$option['name'].'"]');
                break;
            case "image":
                break;
        }
        echo $form->error($model,'detail["'.$option['name'].'"]');
        echo '</div>';
        $i++;
    }
?>

The problem is when giving rules to them. Rules are working just for looking, when i add to rules this

array('detay["ad-title"]', 'required'),

Then, that field is being required and getting a (*). But when i submit the form, then it gives an error saying "Ad.detail["ad-title"]" value isn't defined.

Without rules, i can post and get the posted value correctly using $_POST['Ad']['detail']["ad-title"] etc.

Also; i checked the Yii Framework docs but couldn't find any useful thing except tabular input and Form Builder, and i couldn't implement it to my code. Because i don't want to create variables at my model, i just want to send data using just one variable and rule.

Thanks, çağlar.

Upvotes: 0

Views: 1415

Answers (1)

I did not find any rule regarding this as you are giving.

array('detay["ad-title"]', 'required'),

if ad-title is your table field name, then you may write.

array('ad-title', 'required'),

that's it ...

otherwise you need to learn rules, below is the one of the link where you can learn.

http://www.yiiframework.com/wiki/56/

Thanks.

Upvotes: 0

Related Questions