我创建了一个包含两个标签的网页,每个标签都有一个链接列表。当我单击第一个选项卡上的链接时,第二个选项卡上的链接将被激活。除非它的行号超过第二个选项卡上的行数。输出HTML是正确的。两个标签本身都可以正常工作。
我正在使用Yii 1.1.14,php 5.4.11
控制器操作:
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,
));
}
查看文件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>
这是局部视图_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>
这是局部视图_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>
在帖子上,文件[x] [&#39; id&#39;]设置为x =行号,id为隐藏字段(同样适用于第二个标签行的Listfile) 。单击“重新加载”时,将加载以下操作。它获取x值(行号)并从中确定id值。然后它加载test / uploadFile / id页面。问题是,当我单击第一个选项卡上前三行的重新加载(或删除)链接时,我得到第二个选项卡的ID。当我为第一个选项卡上的最后两行执行此操作时,我得到正确的id值。第二个选项卡上的所有链接都按预期工作,如果单独加载每个选项卡,都会按预期工作。
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,
));
}
答案 0 :(得分:0)
每个标签的帖子索引必须不同。一种方法是使用第二个选项卡的乘数,定义为$ k = 100 *($ i + 1); $ i + 1因为$ i首先是0,而第一行的索引对于两个选项卡都是0。当然,也可以使用其他一些乘数。
<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): $k=($i+1)*100; ?>
<tr id="trow">
<td><?php echo CHtml::activeHiddenField($file, "[$k]id"); ?></td>
<td><?php echo 'fileID: ['.$file['id'].']'; ?></td>
<td><?php
echo CHtml::link('Reload File','#',
array('submit'=>array('setupFileList','id'=>$k),
'id' => 'setup_' . $k . '_reload',
'value' => (int) $k,
'name' => 'setupFileList',
));
?></td>
<td><?php
echo CHtml::link('Delete','#',
array('submit'=>array('fileListDelete','id'=>$k),
'id' => 'setup_' . $k . '_delete',
'value' => (int) $k,
'name' => 'delete',
'confirm' => 'Are you sure you want to delete file '.$file['id'].'?',
));
?></td>
</tr>
<?php endforeach; ?>
</table>
或者,从视图文件(test5)传递偏移量,其中第二个和后续选项卡的偏移量是所有先前选项卡中的条目数(即第二个选项卡:$ offset = count($ templateList))。然后使用$ i + $ offset来代替上面的$ k: