我有一个包含团队组的页面,delete team
旁边有按钮。当团队不在组中时,它具有将团队添加到组的复选框和按钮。我在 actionView 中写道,它将呈现一个包含团队的组列表。
GroupController 中的 actionView
public function actionView($id) {
$group = $this->loadModel($id);
$teamlst = Group::getAllTeamOfGroup($id);
$teamnotlst = Group::getAllTeamNotInGroup($id);
// Submit
$preSelectedItems = array();
if (isset($_POST['teamlist'])) {
$preSelectedItems = array();
foreach ($_POST['teamlist'] as $selectedItem) {
$preSelectedItems[] = $selectedItem;
}
}
// $teamNo = CHtml::listData($teamnotlst, 'id', 'name');
//Delete
$this->render('view', array(
'model' => $group,
'teamlst' => $teamlst,
'preSelectedItems'=> $preSelectedItems,
'group_id'=>$id,
'teamnotlst' => $teamnotlst,
));
if(isset($_POST['btndeleteteam'])){
TeamGroup::model()->deleteTeamGroup($team->id, $model->ID);
}
}
在视图文件中
<div class="action">
<input type="submit" name="btnupdateteam" value="Update Team">
</div>
<?php echo CHtml::endForm(); ?>
<div class ="team">
<div class="column1">
<?php foreach ($teamlst as $team): ?>
<div class="row">
<?php
echo $team->name;
?>
<input type="submit" name="btndeleteteam" value="Delete Team">
<?php
if(isset($_POST['btndeleteteam'])){
TeamGroup::model()->deleteTeamGroup($team->id, $model->ID);
}?>
</div>
</div><!-- comment -->
<?php endforeach; ?>
<?php
$preSelectedItems = array();
if (isset($_POST['teamlist'])) {
$preSelectedItems = array();
foreach ($_POST['teamlist'] as $selectedItem) {
$preSelectedItems[] = $selectedItem;
}
}
$teamNo = CHtml::listData($teamnotlst, 'id', 'name');
echo CHtml:: checkBoxList('teamlist', $preSelectedItems, $teamNo);
?>
</div>
<div class ="team available">
</div>
我的想法是,当您单击delete team
按钮时,它将从组中删除团队,我有一个方法
TeamGroup::model()->deleteTeamGroup($team->id, $model->ID);
当团队不在组中时,它将具有复选框和更新按钮,如果选中复选框,则会将团队添加到组中。
感谢提前!