Answer the question
In order to leave comments, you need to log in
How to display a field in a model form to save data from it to a linked table?
Colleagues. hello.
Began to study Yii 1.1.16
Faced a problem:
There are two related tables (models) - owner and number.
The owner holds the record ID from the number table, i.e. one line owner can match several numbers.
How to display on the page for creating a new owner instead of numberid a field that will be saved to the associated table number?
You need to change the code in _form.php, but how?
<?php
/* @var $this OwnerController */
/* @var $model Owner */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'owner-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'owner'); ?>
<?php echo $form->textField($model,'owner',array('size'=>40,'maxlength'=>40)); ?>
<?php echo $form->error($model,'owner'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'numberid'); ?>
<?php echo $form->textField($model,'numberid'); ?>
<?php echo $form->error($model,'numberid'); ?>
</div>
<div class="row">
<?php echo $form->dropDownList($model,'type',
Type::All(),
array('empty' => '(Select a type)')
) ;?>
<?php echo $form->error($model,'type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'InfoData'); ?>
<?php echo $form->textField($model,'InfoData',array('size'=>60,'maxlength'=>60)); ?>
<?php echo $form->error($model,'InfoData'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<div class="row">
<?php echo $form->labelEx($model,'numberid'); ?>
<?php echo $form->textField($model,'numberid'); ?>
<?php echo $form->error($model,'numberid'); ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question