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


How to access protected variable in Zend forms?

我正在尝试使用运输成本下拉的动态值创建一个动态多选选择,

数组进入并创建select输入fine,但忽略了受保护的值。这对我来说毫无意义。我甚至尝试使用公共getter来访问受保护的值,但它仍然是空白的。

        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
            );
        }

这是放置在表单的init函数中的$form代码:

    $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));

由于您没有创建ORed_Shipping_LabelFactory的实例,因此您不能使用实例变量(以$this开头的变量是实例变量)。

   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
                );
            }