我是使用Symfony v2.0的新手,我想知道为什么我使用了不同的if
方面,但最终价格却被覆盖了。最终价格仅使用最近使用过的$this->price
,并且使我的价格计算器感到困惑,例如:
if ($this->mode == 'coaching')
{
$n = $this->orderDetails->{'hours-number'};
if($n == 1)
$this->price = 5;
else if($n == 2)
$this->price = 35;
else if($n == 3)
$this->price = 45;
else if($n == 4)
$this->price = 55;
else if($n == 5)
$this->price = 65;
$this->eta = '1 Day';
$w = 0;
if ($this->orderDetails->{'option'} == 'wins')
{
$w = $this->orderDetails->{'wins-number'} * 2;
$this->price = $w;
}
$p = 0;
if ($this->orderDetails->{'option'} == 'self')
{
$p = $this->orderDetails->{'wins-number'} * 2.5;
$this->price = $p;
}
最后的$this->price
仅会显示,尽管事实上仅在呼叫“小时数”。当我有多个影响价格的条件时,我应该以不同的方式编写代码吗?
我的函数也用index.html.twig
编写:
function updateOrderArray()
{
var nData = {};
$('*[pp-type="item"]').each(function() {
if ($(this).attr('type') == 'checkbox')
{
nData[ $(this).attr('pp-item-name') ] = $(this).is(':checked');
}
else
{
nData[ $(this).attr('pp-item-name') ] = $(this).val();
}
});
var nJSON = JSON.stringify(nData);
$('input[name="order_details"]').val(nJSON);
checkDivisions();
calculatePrice();
}
function calculatePrice()
{
$('#arena-price').html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
$('#arena-eta').html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
$.ajax({
method: 'POST',
url: '{{ path('service_price') }}',
dataType: 'JSON',
data: {
mode: 'coaching',
order_details: $('input[name="order_details"]').val()
}
})