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
                    );
                }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 如何修改别人网站内的数字,各位接单的私我
  • ¥15 poi怎么在指定位置之后生成多个表格
  • ¥15 nginx在location设置了client_max_body_size依旧报错413
  • ¥15 C#添加WCF服务引用客户端调用方法没有反应
  • ¥15 stm32f103c8t6与esp8266
  • ¥15 使用Hadoop的MapReduce program
  • ¥15 Python发生IndexError错误如何解决?
  • ¥15 如何用matlab搭建激光器
  • ¥15 51单片机两路互补SPWM输出全桥逆变
  • ¥15 outlook左边用户名下拉为啥打不开了