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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀