Страница 1 из 1

как задать условие

СообщениеДобавлено: 02 дек 2014, 17:38
vanred79
Добрый день! Подскажите пожалуйста как в нижеследующем коде задать условие с помощью if - else. Надо чтобы 'class' => 'width200' был для 'field' => 'additional_info', а для остальных 'class' => 'width500'

Код: Выделить всё
 case 'text':
                
$str .= CHtml::activeTextArea($this->model$field, array(
                    
'class' => 'width500',
                    
'id' => $fieldId
                
));
                break; 


Пробовал вот так, не работает :(
Код: Выделить всё

            
case 'text':
                
$str .= CHtml::activeTextArea($this->model$field, array(
                    if (
$field == 'additional_info_'.Yii::app()->language) {'class' => 'width200'} else {'class' => 'width500'},
                    
'id' => $fieldId
                
));
                break;
                

Re: как задать условие

СообщениеДобавлено: 03 дек 2014, 16:51
Foton
А если попробовать так
Код: Выделить всё
case 'text':
                $str .= CHtml::activeTextArea($this->model, $field, array(
                    'class' => ($field == 'additional_info_'.Yii::app()->language) ? 'width200' : 'width500',
                    'id' => $fieldId
                
));
                break; 

Re: как задать условие

СообщениеДобавлено: 03 дек 2014, 22:22
vanred79
Foton писал(а):А если попробовать так
Код: Выделить всё
case 'text':
                $str .= CHtml::activeTextArea($this->model, $field, array(
                    'class' => ($field == 'additional_info_'.Yii::app()->language) ? 'width200' : 'width500',
                    'id' => $fieldId
                
));
                break; 

Работает! Foton спасибо! *THUMBS UP*

Re: как задать условие

СообщениеДобавлено: 09 янв 2015, 07:41
nawaz55
this is very nice post :-)

_______________________
You can easily check out our high quality ccna which prepares you well for ccnp tshoot testking. You can also get success in real computer certifications exam with the quality hodges and selftestengine.