phpmodel-view-controlleryii

How to set a list defined in model with a list from view page:yii 1.1


I have passed a list '$passValue' from my controller to my view form . Now i have to set this list into $emailList which is also a list defined in my model.How it can be done? My code of view form is:

<?php 
    $val=array();
    foreach($passValue as $par){
    array_push($val,$par);  
    }
    echo $form->hiddenField($model,'emailList ',$val,array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>

My js code :

    $.ajax({
        type: 'POST',
        url: '<?php echo CController::createUrl('client/sendMail'); ?>',
        data:{ids:selectbox},
        dataType:'json',
        success:function(data){ 
        if (data.status == 'failure')
            {
            $('#dialogMail div.divForForm').html(data.div);
               }
           },
        error: function(data) { 
         alert("Error occured.please try again");
          }
    });

My controller code to open my dialog:

if (Yii::app()->request->isAjaxRequest)
    {
        echo CJSON::encode(array(
            'status'=>'failure', 
            'div'=>$this->render('_compose', array('passValue '=>$passValue ,'model'=>$model), true)));
        exit;               
    }

Solution

  • You can assign value using html options. But here you are trying to assign an array. first you need to change the array in string and then you can assign. Use json_encode for change the array to string or implode function to convert array in string.

    <?php 
    
          echo $form->hiddenField($model,'emailList',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly','value'=>$val));
    
         ?>