Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.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/1/database/9.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_Zend Framework_Zend Form_Zend Form Element_Zend Form Sub Form - Fatal编程技术网

PHP Zend子表单-查看子表单元素上的脚本装饰器

PHP Zend子表单-查看子表单元素上的脚本装饰器,php,zend-framework,zend-form,zend-form-element,zend-form-sub-form,Php,Zend Framework,Zend Form,Zend Form Element,Zend Form Sub Form,我有一个products表单(请在此坚持),它有一个子表单,由product数组索引标识,每个子表单都包含另一个子表单(子表单异常)由产品ID标识,此子表单包含一个多复选框,该复选框显示每个产品两个选项:选择产品并将其标记为免费 当我添加任何类型的装饰器(理想情况下,我希望添加自定义视图脚本)时,都不会输出任何内容(没有错误)。当我没有为元素指定装饰器时,它会输出表单 布局如下 products sub-form [ selection sub-form [ MultiC

我有一个products表单(请在此坚持),它有一个子表单,由product数组索引标识,每个子表单都包含另一个子表单(子表单异常)由产品ID标识,此子表单包含一个多复选框,该复选框显示每个产品两个选项:选择产品并将其标记为免费

当我添加任何类型的装饰器(理想情况下,我希望添加自定义视图脚本)时,都不会输出任何内容(没有错误)。当我没有为元素指定装饰器时,它会输出表单

布局如下

products sub-form [
    selection sub-form [
        MultiCheckbox element[
            decorator[
                ViewScript[]
            ]
        ]
    ] 
]
这是我的表格。有可能以这种方式实施吗

<?php

/**
 * Properties_Form_Admin_Products
 */

/**
 * Admin form for creating a new property
 *
 * @category    Properties
 * @package     Form
 */
class Properties_Form_Admin_Products extends Cms_Form_DtDd {

    /**
     * @var Properties_Model_Property
     */
    protected $_property;

    /**
     * @var Properties_Manager_Property
     */
    protected $_propertyManager;

    /**
     * @var array
     */
    private $products;

    /**
     * Initialize form (extended from Zend_Form)
     *
     * @return void
     */
    public function init() {
        parent::init();

        $this->_propertyManager = Caboodle_Manager_Factory::get('Property');

        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->setMethod('post')
                ->setAttrib('id', 'product_form')
                ->setAttrib('class', 'page_form admin_form')
                ->setDecorators($this->formDecorators)
                ->setAction($this->getView()->url());

        $subform = $this->addSubform(new Zend_Form_SubForm, 'products')
            ->getSubform('products')
            ->clearDecorators()
            ->addDecorator('FormElements');

        // Add subform for each existing product time.
        foreach ($this->getProducts() as $index => $product) {
            $subform->addSubform(new Zend_Form_SubForm, (string) $index)
                    ->getSubform((string) $product->getId())
                    ->addElements(array(
                        new Zend_Form_Element_MultiCheckbox('selection', array(
                            'label' => $product->getName() . ' ('.$product->getDescription().')',
                            'decorators' => array(
                                // This form displays when the below decorator is commented out
                                array('ViewScript', array(
                                        'viewScript' => '/partials/property-products.phtml',
                                        'category' => 'Products',
                                        'options' => $product
                                    )
                                )
                            ),
                            'multiOptions' => array(
                                'select' => 'Select',
                                'free' => 'Mark as free'
                            )
                        ))
                    ));
        }

        /* buttons */
        $submit = new Zend_Form_Element_Submit('submit_btn');
        $submit->setRequired(false)
                ->setIgnore(true)
                ->setLabel('Add and Pay')
                ->setAttrib('class', 'pos_btn')
                ->setDecorators($this->buttonDecorators);
        $this->addElement($submit);

        $this->addDisplayGroup(
                array('submit_btn'), 'buttons', array('decorators' => $this->plainGroupDecorators)
        );
    }

    /**
     * Validate the form
     *
     * @param  array $data
     * @return boolean
     */
    public function isValid($data) {

        parent::isValid($data);

        return !$this->_errorsExist;
    }

    /**
     * Handle all of the form processing for the login form
     *
     * @param Zend_Controller_Request_Abstract $request
     * @return void
     */
    public function processForm(Zend_Controller_Request_Abstract $request) {
        if ($request->isPost()) {

            if ($this->isValid($request->getPost())) { // valid
                $values = $this->getValues();
            }
        }
    }

    /**
     * @param $products
     * @return $this
     */
    protected function setProducts($products)
    {
        $this->products = $products;
        return $this;
    }

    /**
     * @return array
     */
    public function getProducts()
    {
        return $this->products;
    }

}

我的decorator的语法有点错误,缺少一个外部数组。下面是装饰师应该做的:

'decorators' => array(
    array(
        'ViewScript', array(
            'viewScript' => '/admin/partials/property-products.phtml',
            'category' => 'services',
            'options' => $product
        )
     )
)