gpt4 book ai didi

php - 谁能帮我把它做成一个对象。 (php)

转载 作者:行者123 更新时间:2023-11-30 08:16:49 24 4
gpt4 key购买 nike

嘿,谁能帮我把它做成一个对象。

显然,我的代码并非全部都在这里,但我相信您会明白要点。

<?php
$product_name_1 = $_POST['product_name_1'];
$region_1 = $_POST['region_1'];
$start_date_1 = $_POST['start_date_1'];
$end_date_1 = $_POST['end_date_1'];
$sku_1 = $_POST['sku_1'];

$product_name_2 = $_POST['product_name_2'];
$region_2 = $_POST['region_2'];
$start_date_2 = $_POST['start_date_2'];
$end_date_2 = $_POST['end_date_2'];
$sku_2 = $_POST['sku_2'];

$product_name_3 = $_POST['product_name_3'];
$region_3 = $_POST['region_3'];
$start_date_3 = $_POST['start_date_3'];
$end_date_3 = $_POST['end_date_3'];
$sku_3 = $_POST['sku_3'];
?>



<form action="" method="post" accept-charset="utf-8">
<div id="product_information">
<table id="product_1">
<tr>
<th><label for="product_name">Product Name</label></th>
<th><label for="region">Select A Region</label></th>
<th class="date"><label for="start_date">Start Date</label></th>
<th class="date"><label for="end_date">End Date</label></th>
<th><label for="sku">SKU</label></th>
</tr>
<tr>
<td><input type="text" name="product_name_1" value="" id="product_name_1"></td>
<td><input type="radio" name="region_1" value="upper_north" id="upper_north_1"><label for="upper_north_">Upper North Island</label><br />
<input type="radio" name="region_1" value="lower_north" id="lower_north_1"><label for="lower_north_">Lower North Island</label><br />
<input type="radio" name="region_1" value="south_island" id="south_island_1"><label for="south_island">South Island</label> </td>
<td class="date"><input type="text" class="date" name="start_date_1" value="" id="start_date_1"></td>
<td class="date"><input type="text" class="date" name="end_date_1" value="" id="end_date_1"></td>
<td><input type="text" name="sku_1" value="" id="sku_1"></td>
</tr>
</table>
<span class="product"></span>
<div class="add-product">&nbsp;</div>
</div>

<script type="text/javascript" charset="utf-8">

var i = 1;

$('.add-product').click(function(){
i++;
$('span.product').replaceWith('<table id="product_'+i+'">'
+'<tr>'
+'<th><label for="product_name">Product Name</label></th>'
+'<th><label for="region">Select A Region</label></th>'
+'<th class="date"><label for="start_date">Start Date</label></th>'
+'<th class="date"><label for="end_date">End Date</label></th>'
+'<th><label for="sku">SKU</label></th>'
+'</tr>'
+'<tr>'
+'<td><input type="text" name="product_name'+i+'" value="" id="product_name'+i+'"></td>'
+'<td><input type="radio" name="region'+i+'" value="upper_north" id="upper_north'+i+'"><label for="upper_north'+i+'">Upper North Island</label><br />'
+'<input type="radio" name="region'+i+'" value="lower_north" id="lower_north'+i+'"><label for="lower_north'+i+'">Lower North Island</label><br />'
+'<input type="radio" name="region'+i+'" value="south_island" id="south_island"><label for="south_island">South Island</label> </td>'
+'<td class="date"><input type="text" class="date" name="start_date'+i+'" value="" id="start_date'+i+'"></td>'
+'<td class="date"><input type="text" class="date" name="end_date'+i+'" value="" id="end_date'+i+'"></td>'
+'<td><input type="text" name="sku'+i+'" value="" id="sku'+i+'"></td>'
+'</tr>'
+'</table>'
+''
+'<span class="product"></span>');
});
</script>

最佳答案

您可以使用此对象开始。之后定义保存和检索它的方法。也许还有适当的构造函数,用于从 post 参数创建不同的产品。

class Product {

private $Name;
private $Region;
private $StartDate;
private $EndDate;
private $Sku;

public function setName( $value )
{
//make some validation or manipulation on data here, if needed
$this->Name = $value;
}

public function getName()
{
return $this->Name;
}

public function setRegion( $value )
{
//make some validation or manipulation on data here, if needed
$this->Region = $value;
}

public function getRegion()
{
return $this->Region;
}
public function setStartDate( $value )
{
//make some validation or manipulation on data here, if needed
$this->StartDate = $value;
}

public function getStartDate()
{
return $this->StartDate;
}

public function setEndDate( $value )
{
//make some validation or manipulation on data here, if needed
$this->EndDate = $value;
}

public function getEndDate()
{
return $this->EndDate;
}

public function setSku( $value )
{
//make some validation or manipulation on data here, if needed
$this->Sku= $value;
}

public function getSku()
{
return $this->Sku;
}
}

希望对您有所帮助!

关于php - 谁能帮我把它做成一个对象。 (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2293234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com