Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Multiple Models in yii
    primarykey
    data
    text
    <p>I have 3 tabs on my view file </p> <p><strong>First tab:</strong> student</p> <p><strong>Second tab:</strong> education</p> <p><strong>Third tab:</strong> employment</p> <h2>My Table Structure:</h2> <p><strong>student table:</strong></p> <pre><code>+-------------+------------+--------------+------------+-------------+ | id(PK) | lead_id | st_name | st_email | st_phone | +-------------+------------+--------------+------------+-------------+ </code></pre> <p><strong>Lead Details:</strong></p> <pre><code>+-------------+-------------+ | id(PK) | lead_ref_id | +-------------+-------------+ </code></pre> <p><strong>Education</strong></p> <pre><code>+-------------+------------+--------------+--------------+ | id(PK) | lead_id |education_type|education_year| +-------------+------------+--------------+--------------+ </code></pre> <p><strong>Employment:</strong></p> <pre><code>+-------------+------------+---------------+---------------------+ | id(PK) | lead_id |Employment_type|Employment_experience| +-------------+------------+---------------+---------------------+ </code></pre> <p>When I go to the update action, I have to show data according to the lead_id</p> <p><strong>My student view file code:</strong></p> <pre><code>&lt;div class="form"&gt; &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'lead-student-detail-form', // Please note: When you enable ajax validation, make sure the corresponding // controller action is handling ajax validation correctly. // See class documentation of CActiveForm for details on this. 'enableAjaxValidation'=&gt;false, 'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'), )); ?&gt; &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'st_name'); ?&gt; &lt;?php echo $form-&gt;textField($model,'st_name',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt; &lt;?php echo $form-&gt;error($model,'st_name'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'st_email'); ?&gt; &lt;?php echo $form-&gt;textField($model,'st_email',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt; &lt;?php echo $form-&gt;error($model,'st_email'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model,'st_phone'); ?&gt; &lt;?php echo $form-&gt;textField($model,'st_phone'); ?&gt; &lt;?php echo $form-&gt;error($model,'st_phone'); ?&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- form --&gt; </code></pre> <p><strong>My education view code</strong></p> <pre><code> &lt;div class="form"&gt; &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'lead-target-education-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'=&gt;false, )); ?&gt; &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt; &lt;?php echo $form-&gt;errorSummary(array($target)); ?&gt; &lt;/div&gt; &lt;?php echo $form-&gt;labelEx($target,'education_type'); ?&gt; &lt;?php echo $form-&gt;textField($target,'education_type'); ?&gt; &lt;?php echo $form-&gt;error($target,'education_type'); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php echo $form-&gt;labelEx($target,'academic_year'); ?&gt; &lt;?php echo $form-&gt;textField($target,'academic_year[]'); ?&gt; &lt;?php echo $form-&gt;error($target,'academic_year'); ?&gt; &lt;/div&gt; </code></pre> <p>How should i write the action update code so data shows according to the <code>lead_id</code>, not by the primary key <code>id</code> and get update according to the <code>lead_id</code>.</p> <p><em><strong>Update From Comment</em></strong></p> <p>There is a one to many relationship between lead and education tables.</p> <pre><code>+-------------+------------+--------------+--------------+ | id(PK) | lead_id |education_type|education_year| +-------------+------------+--------------+--------------+ | 1 | 1 | 10 | 2003 | +-------------+------------+--------------+--------------+ | 2 | 1 | 12 | 2005 | +-------------+------------+--------------+--------------+ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload