duanhuayong6687 2015-01-01 21:40
浏览 8
已采纳

如何为用户创建一个从对象集合中删除对象的选项?

Here is my code:

$printcoll = $_SESSION['ObjColl'];


for($i = 0;$i < $printcoll->getlineCount();$i++){
$li = $printcoll -> getLineItem($i);
$item = $li->getItem();
if ($item instanceof Product) {
 print "Bike ID - ";
} 
print $item-> getId();


if ($item instanceof Product) {
 print "&nbsp Price &pound"; 

}
print $item-> getPrice();

if ($item instanceof Product) {
 print "&nbsp Quantity - "; 

}

print $li->getQuantity();
echo "</br>";

Here is what the ObjectCollection looks like:

ObjectCollection Object ( [line_items_array:ObjectCollection:private] => Array ( [0] => LineItem Object ( [item:LineItem:private] => Product Object ( [id] => 1 [name] => Yamaha [price] => 10000 ) [quantity:LineItem:private] => 3 ) [1] => LineItem Object ( [item:LineItem:private] => Product Object ( [id] => 4 [name] => Kawasaki [price] => 12000 ) [quantity:LineItem:private] => 7 )

The output of the For loop is:

Bike ID - 1 Price £10000 Quantity - 3

Bike ID - 4 Price £12000 Quantity - 7

The ObjectCollection is made up of Product objects. How do i add an option into the for loop so the user can delete a "Product" object out of the ObjectCollection class?

public function delLineItem($line_item) is the function within the ObjectCollection class. But how do i integrate that into a OPTION in the for loop because the user may or may not to delete it?

So for example, i want the output of the for loop to be :

Bike ID - 1 Price £10000 Quantity - 3 DELETE BUTTON

So if the user clicks on the delete button, it will delete that specific product out of the object collection. Thanks

  • 写回答

1条回答 默认 最新

  • doujiao3016 2015-01-01 21:56
    关注

    you have to link back to your current script and create an action, for example called Delete...

    Cjeck out the if block to the top, add your code for deleting the item there... Further down you will see a Delete link for activating the action...

    $printcoll = $_SESSION['ObjColl'];
    
    //Code for delete operation
    if (is_set($_GET['delete'])) {
        $id = $_GET['delete'];
        echo "Deleting $id...";
    }
    
    
    for($i = 0;$i < $printcoll->getlineCount();$i++){
    $li = $printcoll -> getLineItem($i);
    $item = $li->getItem();
    if ($item instanceof Product) {
     print "Bike ID - ";
    } 
    print $item->getId();
    
    //Add a delete link
    print "<a href='" . $_SERVER['PHP_SELF'] . "?delete=" . $i . "'>Delete</a>";
    
    
    if ($item instanceof Product) {
     print "&nbsp Price &pound"; 
    
    }
    print $item-> getPrice();
    
    if ($item instanceof Product) {
     print "&nbsp Quantity - "; 
    
    }
    
    print $li->getQuantity();
    echo "</br>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?