Reputation: 2080
I want to make text area in cactiveform in yii dynamically. but I am getting error i.e. "Property "Verse.translation" is not defined"
I have translation_text
field, not translation
field in my db. Secondly $trans['translation_text']
display the verse translation but when i keep it in textArea it is giving error. as i have described.
I have a code.
<?php foreach($model->verseTranslations as $trans) { ?>
<?php $model->translation = $trans['translation_text']; ?>
<?php echo $form->textArea($model,'translation',array('rows'=>6, 'cols'=>50)); ?>
<?php } ?>
But i do not know how to keep value $trans['translation_text']
in textArea.
Any help will be appreciated.
Thanks
Upvotes: 0
Views: 5391
Reputation: 119
Do it like this :
<?php foreach($model->verseTranslations as $trans) { ?>
<?php echo $form->textArea($model,'translation',array('value'=>$trans['translation_text'],'rows'=>6, 'cols'=>50)); ?>
<?php } ?>
And in your model as RobM said earlier, but don't forget to add a validator in you Verse class for 'translation' attribute ! :
class Verse extends CActiveRecord
{
public $translation;
public function rules()
{
return array(
array(
'translation',
'safe',
'on'=>'',
),
//others validators here
);
}
}
Upvotes: 1
Reputation: 432
Add translation property to Verse class in models
class Verse extends CActiveRecord
{
public $translation;
Upvotes: 0
Reputation: 749
Just replace the second parameter in $form->textArea
with $trans['translation_text']
, so that it becomes:
<?php echo $form->textArea($model, $trans['translation_text'], array('rows'=>6, 'cols'=>50)); ?>
The second parameter is the value of the textArea, so the value of any variable here will show up as the default value of the text area element.
Upvotes: 0