Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert data in two different tables from single Controller in Yii
    primarykey
    data
    text
    <p>I have two different table and i want to insert data in both of them at a time.</p> <p><strong>ONE table is verse</strong></p> <pre><code>verse(id, topic_id, surah_id, verse_text) // id is primary key, </code></pre> <p><strong>Second table is verse_translations</strong></p> <pre><code>verse_translations(id, verse_id, language_id, translations_text) // id is primary key, language_id is foreign key references with language table, // verse_id is foreign key references with verse table. </code></pre> <p><strong>Verse Create File (_form.php)</strong></p> <pre><code>&lt;div class="form"&gt; &lt;?php $form = $this-&gt;beginWidget('CActiveForm', array('id'=&gt;'verse-form', 'enableAjaxValidation'=&gt;true)); ?&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, 'verse_text'); ?&gt; &lt;?php echo $form-&gt;textArea($model, 'verse_text', array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt; &lt;?php echo $form-&gt;error($model,'verse_text'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model, 'verse_translations'); ?&gt; &lt;p class="&lt;?php echo "tran".$model-&gt;id ?&gt;"&gt; &lt;?php $errors = array_filter($model-&gt;verseTranslations); if(!empty($errors)) { foreach($model-&gt;verseTranslations as $vt) { echo $form-&gt;textArea($model, 'translation_text', array('value'=&gt;$vt['translation_text'], 'rows'=&gt;6, 'cols'=&gt;50)); } } ?&gt; &lt;/p&gt; &lt;/div&gt; &lt;div class="row buttons"&gt; &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt; &lt;/div&gt; &lt;?php $this-&gt;endWidget(); ?&gt; &lt;/div&gt;&lt;!-- form --&gt; </code></pre> <p>As you may see from _form file, I have called the data from verse_translations table.</p> <p><strong>Now my questions are:</strong></p> <p>How I keep the value of textArea that it will go in an array in controller? And How can I insert data in verse_translation table from verse create controller.</p> <p>The output of _form file is like that.</p> <p><strong>Verse Create Controller Code.</strong></p> <pre><code>public function actionCreate() { $model=new Verse; // Uncomment the following line if AJAX validation is needed // $this-&gt;performAjaxValidation($model); if(isset($_POST['Verse'])) { $model-&gt;attributes=$_POST['Verse']; if($model-&gt;save()) $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id)); } $this-&gt;render('create',array( 'model'=&gt;$model, )); } </code></pre> <p>Hope you understand it clearly.</p> <p>Thanks</p>
    singulars
    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