2011-04-28 41 views
1

我工作的一個電子商務網站,當用戶添加產品到購物籃的第一次,我碰到下面的錯誤,PHP的幫助,會話錯誤可能嗎?

遇到

一個PHP錯誤

嚴重性:注意

消息:未定義指數:ORDERDETAILS

文件名:庫/ MY_Cart.php

行號:59一個PHP錯誤是 遇到

嚴重性:警告

消息:不能更改頭 信息 - 頭已經 發送(輸出開始 /無功/網絡/虛擬主機/ akulaliving .COM/httpdocs資料/ CI-1.7.3 /庫/ Exceptions.php:166)

文件名:庫/ session.php文件

行號:662

的增加了產品與下面的代碼籃下,

if ($this->input->post('btnAddToBag')) 
     { 

      $derivativeId = $this->input->post('selDerivative-1'); 
      $quantity = $this->input->post('selQuantity'); 
      $derivative = $this->Product_model->GetProducts(array('pdId' => $derivativeId), 'small'); 

      // Add item to shopping bag. 
      $attributes = $this->Product_model->GetProductDerivatives(array('pdId' => $derivativeId)); 
      $this->Checkout_model->AddProduct($derivative, $attributes, $quantity); 
      $this->data['message'] = 'Item added to Shopping Bag.'; 

      // Update Delivery Price 
      $this->Checkout_model->updateDelivery(49); 

      //get the bag details 
      $this->data['items'] = $this->Checkout_model->GetProducts();   
     } 

被調用的模型函數是這樣的,

function AddProduct($derivative, $attributes, $quantity) 
{ 
    $data = array(
     'id'   => $derivative->pdId, 
     'qty'  => $quantity, 
     'price'  => ($derivative->productSavingType == 'none' ? $derivative->productPrice : $derivative->productSavingPrice), 
     'name'  => $derivative->productTitle, 
     'attributes' => $attributes['attributeValues'], 
     'refNo'  => $derivative->pdRefNo, 
     'productId' => $derivative->productId, 
     'set'  => $derivative->productIsSet, 
     'hasImage' => $derivative->hasImage, 
     'imageUrl' => $derivative->imageUrl, 
     'imageAlt' => $derivative->imageAlt, 
     'stockLevel' => $derivative->pdStockLevel, 
     'leadTime' => $derivative->pdLeadTime 
    ); 

    $data['nonDiscountedPrice'] = $data['price']; 
    if ($derivative->productSavingType == 'end-of-season') 
    { 
     $data['nonDiscountedPrice'] = $derivative->productPrice; 
    } 

    $this->cart->insert($data); 
} 

錯誤是抱怨碼是以下,

function _insert($items=array()) 
{ 
    if (isset($items['options']) AND count($items['options']) > 0) 
    { 
     $rowid = md5($items['id'].implode('', $items['options'])); 
    } 
    else 
    { 
     $rowid = md5($items['id']); 
    } 

    if (isset($this->_cart_contents[$rowid])) 
    { 
     if (!isset($items['qty'])) 
     { 
      return FALSE; 
     } 

     // Already Exists, we need to update the total for this item 
     $new_qty = $items['qty']; 
     $items['qty'] = $items['qty'] + $this->_cart_contents[$rowid]['qty']; 

     $items['rowid'] = $rowid; 

     if ($this->_update($items)) 
     { 
      return TRUE; 
     } 
     return FALSE; 
    } 

    // Doesn't exist, we need to insert this item. 
    if (parent::_insert($items)) 
    { 
     // Update our total. 
     if (isset($this->_cart_contents[$rowid])) 
     { 
      $this->real_total_items += $this->_cart_contents[$rowid]['qty']; 
      if ($this->_cart_contents['orderDetails']['discount'] > 0) 
      { 
       $this->_cart_contents[$rowid]['price'] = $this->_cart_contents[$rowid]['nonDiscountedPrice']; 
       $this->_save_cart(); 
      } 
     } 
     return TRUE; 
    } 
    return FALSE; 
} 

回答

0

您在使用它這個

解決這一警告之前定義的變量的缺省值。

1

Joomla?這是一條通知,$this->_cart_contents['orderDetails']在使用前未定義。你可以事先定義它,或關閉通知,它應該消失。

1

我敢打賭,你的PHP已經輸出了NOTICE和它的導致會話頭文件已經發送錯誤。

查找你的php.ini的error_reporting行並將其更改爲這個

error_reporting = E_ALL & ~E_NOTICE 

重新啓動Apache實例,看看是否能解決問題。

0

您可能已將您的服務器配置設置爲顯示E_NOTICE的PHP錯誤(這對於開發來說是正常的)。 由於生成了E_NOTICE(MY_Cart.php),因此首先向瀏覽器迴應。 因爲已經有瀏覽器輸出,所以會出現警告「無法修改標題信息」(libraries/Session.php)。可能是因爲它正在執行header()函數或類似的東西。

您可以通過修復E_NOTICE的原因(在'orderDetails'鍵上忘記isset檢查?)或通過在代碼的開頭設置error_reporting(E_ALL & ~E_NOTICE)隱藏E_NOTICE來解決此問題。

0
if (**$this->_cart_contents['orderDetails']['discount'] > 0**) 
     { 
      $this->_cart_contents[$rowid]['price'] = $this->_cart_contents[$rowid]['nonDiscountedPrice']; 
      $this->_save_cart(); 
     } 

由於:: _ cart_contents ['orderDetails'] var不存在,CI會拋出通知消息。

如果你不想改變你的php.ini的錯誤設置,你可以如下改變它,試試:

if (isset($this->_cart_contents['orderDetails']['discount'])&& ($this->_cart_contents['orderDetails']['discount']>0))