因此,我有一个foreach循环,用于显示所有产品和产品信息。我希望每个项目都有一个删除按钮。
{
"$schema" : "https://json-schema.org/schema#",
"type" : "object",
"properties" :
{
"messages" :
{
"type" : "array",
"items" :
{
"properties" :
{
"name" :
{
"type" : "string"
},
"id" :
{
"type" : "string"
},
"signals" :
{
"type" : "object"
},
"properties" :
{
"start_bit" :
{
"type" : "object",
"properties" :
{
"name" :
{
"type" : "string"
},
"bit_length" :
{
"type" : "string"
},
"factor" :
{
"type" : "string"
},
"offset" :
{
"type" : "string"
}
},
"required" : ["name", "bit_length", "factor", "offset"]
}
}
},
"required": ["name", "id", "signals"]
}
}
}
}
答案 0 :(得分:0)
您可以将其附加到您的foreach循环中:
public abstract class PivotRequestFactory
{
public abstract PivotRequest GetPivotRequest();
}
public class ConcretePivotRequestFactory : PivotRequestFactory
{
public ConcretePivotRequestFactory()
{
}
public override PivotRequest GetPivotRequest()
{
try
{
return new PivotRequest();
}
catch (Exception ex)
{
throw;
}
}
}
private PivotRequest GetPivotRequest(string DataSetName)
{
PivotRequestFactory factory = null;
try
{
switch (DataSetName)
{
case DatasetNames.Default:
if (IsTrue) { factory = new ConcretePivotRequestFactory(); }
else { factory = new ConcretePivotRequestFactory2); }
break;
case DatasetNames.SoSo:
if (IsTrue) { factory = new ConcretePivotRequestFactory3(); }
else { factory = new ConcretePivotRequestFactory4(); }
break;
default:
break;
}
}
catch (Exception)
{
throw;
}
return factory.GetPivotRequest();
}
添加以上行后,您必须将要删除的产品ID传递到echo "<a href='YOUR_DELETE_PAGE.php?delete_id={$id}'>Delete</a>"
中。
最后,在您的$_SESSION['cart']
中,您可以执行以下操作:
YOUR_DELETE_PAGE.php