I created a web page with two tabs, each page having a list of links. When I click on a link on first tab, the link on the second tab is activated. That is unless its a row number that exceeds the number of rows on the second tab. The output HTML is correct. Both tabs by themselves work fine.
I am using Yii 1.1.14, php 5.4.11
Controller Action:
public function actionTest5() {
$fileNew = new File;
$criteria = new CDbCriteria;
$criteria->select='id,name,description';
$criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
$criteria->order='t.date_updated desc, t.date_entered desc';
$criteria->limit=5;
$templateList=File::model()->findAll($criteria);
$criteria = new CDbCriteria;
$criteria->select='id,name,description';
$criteria->condition='t.user_id='.(int)Yii::app()->user->id;;
$criteria->order='t.date_updated desc, t.date_entered desc';
$criteria->limit=3;
$listFile= Listfile::model()->findAll($criteria);
$docI = new Document;
$fileNew = new File;
$url = Yii::app()->createUrl('test/setup');
if(isset($_POST['File']) OR isset($_POST['Document']))
$this->redirect($url);
$this->render('test5', array(
'model'=>$docI,
'templateList'=>$templateList,
'listFile'=>$listFile,
'fileNew'=>$fileNew,
));
}
View File test5:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'setup-form',
'enableClientValidation'=>true,
));
$tabArray=array();
$tabArray["Tab1"] = array(
'id'=>'1',
'content'=>$this->renderPartial('_testTab1',
array(
'tabNum'=>1,
'form'=>$form,
'model'=>$model,
'templateList'=>$templateList,
),TRUE));
$tabArray["Tab2"] = array(
'id'=>'2',
'content'=>$this->renderPartial('_testTab2',
array(
'tabNum'=>2,
'form'=>$form,
'model'=>$model,
'listFile'=>$listFile,
),TRUE));
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>$tabArray,
'id'=>'MyTab-Menu',
));
?>
<?php $this->endWidget(); ?>
</div>
This is the partial view _testTab1:
<table class="setup">
<?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
<?php foreach ($templateList as $i=>$file): ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFile','id'=>$i),
'id' => 'setup_' . $i . '_reload',
'value' => (int) $i,
'name' => 'setupFile',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileDelete','id'=>$i),
'id' => 'setup_' . $i . '_delete',
'value' => (int) $i,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
This is the partial view _testTab2:
<table class="setup">
<?php echo '<thead><th></th><th>File Name</th><th>Load File</th><th>Delete</th></thead>' ?>
<?php foreach ($listFile as $i => $file): ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$i]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFileList','id'=>$i),
'id' => 'setup_' . $i . '_reload',
'value' => (int) $i,
'name' => 'setupFileList',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileListDelete','id'=>$i),
'id' => 'setup_' . $i . '_delete',
'value' => (int) $i,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
On post, the File[x]['id']'s are set with the x=row number and id being the hidden field (same applies to Listfile for second tab rows). When Reload is clicked, the following action is loaded. It gets the x value (row number) and from that determines the id value. Then it loads the test/uploadFile/id page. The problem is that when I click on the Reload (or delete) link for the first three rows on the first tab, I get the id for the second tab. When I do this for the last two rows on the first tab, I get the correct id value. All links on the second tab work as expected as do each of the tabs if they are loaded individually.
public function actionSetupFile($id) {
$fileName='';
if(isset($_POST['File'])) {
if(isset($_POST['File'][(int)$id]['id'])) {
$selected = $_POST['File'][(int)$id]['id'];
$file=new File;
$fileName=$file->getFileName($selected);
$url = Yii::app()->createUrl('test/UploadFile/'.CHtml::encode((int)$selected));
}
} else {
$msg = 'Unable to complete request to upload file; try again ';
$url = Yii::app()->createUrl('test/setup');
}
$this->redirect($url, array(
'fileName'=>$fileName,
));
}
public function actionSetupFileList($id=null) {
$fileName='';
if(isset($_POST['Listfile'])) {
if(isset($_POST['Listfile'][(int)$id]['id'])) {
$selected = $_POST['Listfile'][(int)$id]['id'];
$file=new Listfile;
$fileName=$file->getFileListName($selected);
$url = Yii::app()->createUrl('test/UploadFileList/'.CHtml::encode((int)$selected));
}
} else {
$msg = 'Unable to complete request to upload file; try again ';
$url = Yii::app()->createUrl('test/setup');
}
$this->redirect($url, array(
'fileName'=>$fileName,
));
}