1

제품 배열 인덱스로 식별되는 하위 폼이 있고 각 하위 폼에 다른 하위 폼이 포함 된 제품 폼 (여기에 나와 고정하십시오)이 있습니다. (subformception)은 제품 ID로 식별되며이 하위 양식에는 각 제품에 두 가지 옵션을 표시하는 다중 확인란이 있습니다. 제품을 선택하고이를 무료로 표시합니다.PHP Zend Subform - 하위 폼 요소의 스크립트 데코레이터보기

데코레이터를 추가하면 (이상적으로 사용자 정의보기 스크립트를 추가하려고합니다.) 아무 것도 출력되지 않습니다 (오류없이). 요소에 데코레이터를 지정하지 않으면 양식을 출력합니다.

레이아웃은 다음과 같습니다.

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

} 

감사합니다 :) 나단

답변

1

내 장식의 구문이 약간 잘못 하나 개의 외부 배열이 부족했다. 다음은 장식 자의 모양입니다.

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