Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何访问Zend表单中的受保护变量?_Php_Oop_Zend Framework_Zend Form_Zend Form Element - Fatal编程技术网

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

Php 如何访问Zend表单中的受保护变量?,php,oop,zend-framework,zend-form,zend-form-element,Php,Oop,Zend Framework,Zend Form,Zend Form Element,我正在尝试创建一个动态多选项选择,使用运输成本下拉列表的动态值 数组进入并创建select输入,但忽略受保护的值。这对我来说毫无意义。我甚至尝试使用公共getter访问受保护的值,但它仍然是空的 protected $_regular = 4.95; protected $_oneDay = 14.95; protected $_twoDay = 14.95; public function getSh

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

数组进入并创建select输入,但忽略受保护的值。这对我来说毫无意义。我甚至尝试使用公共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));

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


发布的代码看起来是正确的。您可以发布初始化$form对象的代码吗?问题可能是,您试图像静态方法一样调用
getShippingOpts()
?尝试将静态关键字添加到函数和属性中(并将
$this->\u regular
修复为
self::$\u regular
。非常感谢,现在完全有意义了,我的理想方案是从db设置这些变量,所以看起来我毕竟需要一个实例。
   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
                );
            }