Fatal error: Call to a member function getObject() on a non-object in

Fatal error: Call to a member function getObject() on a non-object in

我正在开发一个电子商务网站卡在这个地方我有 SOF post 这个错误但没有帮助我 much.Aim 是根据优惠券代码向客户提供折扣entered.see任何人都可以帮助我。

<?php
/**
  * Consider and apply voucher codes
  * Types of voucher code
  * - = FIXED AMOUNT OFF
  * % = PERCENTAGE OFF
  * s = SET NEW SHIPPING COST
  * @param voucherCode String
  * @return void
  */
  if(isset($_POST["submit"])){
  $code=$_POST["code"];
  $coupon=new coupon();
  $coupon->Vouchers($code);
  }

  class coupon {

   function Vouchers( $voucherCode )
  {
    //The voucher code value is checked to ensure it is not empty 
    // (as per point 1)
    if( $voucherCode != '' )
    {
      // we need the date, to see if the voucher has expired
      $cts = date('Y-m-d H:i:s');
      $voucherCode=$this->registry;
      $voucher_sql = "SELECT *, if('{$cts}' > expiry, 1, 0)
                        AS expired FROM code
                      WHERE code='{$voucherCode}' LIMIT 1";
                      $voucher_sql=$this->registry;
      $this->registry->getObject('code')->executeQuery( $voucher_sql );
      if( $this->registry->getObject('code')->numRows() == 0 )
      {
        $this->voucher_notice = 'Sorry, the voucher code you entered
            is invalid';
      }
      else
      {
        $voucher = $this->registry->getObject('code')->getRows();
        if( $voucher['active'] == 1 )
        {
          if( $voucher['expired'] == 1 )
          {
            $this->voucher_notice = 'Sorry, this voucher has 
                expired';
            return false;
          }
          else
          {
            // check to see there are some vouchers, and customer
            // has enough in their basket (points 3 and 4)
            if( $voucher['num_vouchers'] != 0 )
            {
              if( $this->cost >= $voucher['min_cost'] )
              {
                $this->discountCode = $voucherCode;
                $this->discountCodeId = $voucher['id'];
                // If the discount operation is a percentage, then
                // the discount value is applied to the basket cost
                // to calculate that percentage. This amount is then
                // deducted from the order cost, giving a "discount
                // value"% discount from the order.
                if( $voucher['operation'] == '%' )
                {
                  $this->cost = $this->
              cost - (($this->cost)/100)*$voucher['amount'];
                  $this->voucher_notice = 'A ' 
                      . $voucher['amount'] 
                      . '% discount has been applied to your order';
                  return true;
                  // If the discount operation is a subtraction, then 
                  // the discount amount from the discount code is 
                  // deducted from the order cost, and the order cost 
                  // is updated to reflect this.
                }
                elseif( $voucher['operation'] == '-' )
                {
                  $this->cost = 
                      $this->cost - $voucher['amount'];
                  $this->voucher_notice = 'A discount of &pound;'
                      . $voucher['amount'] 
                      . ' has been applied to your order';
                  return true;
                  // Finally, if the discount operation is set to s 
                  // then, we set the shipping cost to the discount 
                  // value. This could allow us to set free shipping,
                  // or just reduce shipping costs.
                }
                elseif( $voucher['operation'] == 's' )
                {
                  $this->shipping_cost = $voucher['amount'];
                  $this->voucher_notice = 'Your orders shipping cost
                      has been reduced to &pound;' 
                      . $voucher['amount'];
                  return true;
                }
              }
              else
              {
                $this->voucher_notice = 'Sorry, your order total is 
                    not enough for your order to qualify for this 
                    discount code';
                return false;
              }
            }
            else
            {
              $this->voucher_notice = 'Sorry, this was a limited
                  edition voucher code, there are no more instances
                  of that code left';
              return false;
            }
          }
        }
        else
        {
          $this->voucher_notice = 'Sorry, the vocuher code you
              entered is no longer active';
          return false;
        }
      }
    }
  }
  }
  ?>

现在 运行 我得到这个代码 致命错误:在

中的非对象上调用成员函数 getObject()

这是我的 html 表格

<form method="post" action="a.php">
    Enter The Coupon Code:<br />
    <input name="code[]" type="text" size="10" />
    <br />
    <input type="submit" name="submit" value="submit" />
    </form>

看起来错误是

$this->registry->getObject

现在您在任何地方都没有显示正在注入注册表,所以这就是问题所在。我假设您正在使用一个框架,并期望这个 class 是容器感知的,但事实并非如此。所以注入注册表,或者在构造函数中实例化它。