doubaolan2842 2012-04-03 03:39
浏览 12
已采纳

如何在Zend表单中访问受保护的变量?

i am trying to create a dynamic multioption select using dynamic values for a shipping cost pulldown,

the array comes in and creates the select input fine but the protected values are omitted. this makes no sense to me. i even tried using a public getter to access the protected value but it still comes in blank.

        protected $_regular     = 4.95;
        protected $_oneDay      = 14.95;
        protected $_twoDay      = 14.95;

        public function getShippingOpts(){

            return array(
                "regular"=>"Regular 5-7 Business Days $".$this->_regular,
                "two-day"=>"Express 3-4 Business Days $".$this->_twoDay,
                "one-day"=>"Overnight 1-2 Business Days $".$this->_oneDay
            );
        }

here is the $form code placed within the form's init function:

    $shType = new Zend_Form_Element_Radio("sh_type");
    $shType->setLabel("Please select a type of shipping")
            ->setAttrib('class', 'co-shipping-type')
            ->setRequired(true)
    ->setMultiOptions(ORed_Shipping_LabelFactory::getShippingOpts());
    $shTypeToSubmit = new Zend_Form_Element_Hidden('speed');
    $shipping2->addElements(array($shType, $shTypeToSubmit));
  • 写回答

1条回答 默认 最新

  • dqtu14636 2012-04-03 09:22
    关注

    Since you are not creating instance of ORed_Shipping_LabelFactory hence you cannot use instance variables (variables which starts with $this are instance variables) .

       static $_regular     = 4.95;
                static $_oneDay      = 14.95;
                static $_twoDay      = 14.95;
    
                public static function getShippingOpts(){
    
                    return array(
                        "regular"=>"Regular 5-7 Business Days $".self::$_regular,
                        "two-day"=>"Express 3-4 Business Days $". self::$_twoDay,
                        "one-day"=>"Overnight 1-2 Business Days $". self::$_oneDay
                    );
                }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式