本文整理汇总了PHP中Zend_Form_Element_File::addDecorator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element_File::addDecorator方法的具体用法?PHP Zend_Form_Element_File::addDecorator怎么用?PHP Zend_Form_Element_File::addDecorator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element_File
的用法示例。
在下文中一共展示了Zend_Form_Element_File::addDecorator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSaveProductForm
public function getSaveProductForm($id)
{
$form = new Zend_Form();
//get product whitch want update
$productMapper = new Application_Model_ProductMapper();
$product = new Application_Model_Product();
if ($id) {
$product = $productMapper->getProductById($id);
}
// Set the method for the display form to POST
$form->setMethod('post');
$form->setAttribs(array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'));
$decoratorField = new My_Decorator_Field();
$elements = array();
//Add id hidden field
$input = new Zend_Form_Element_Hidden('id', array('value' => $id));
$elements[] = $input;
// Add name field
$input = new Zend_Form_Element_Text('name', array('required' => true, 'label' => 'Name:', 'id' => 'name', 'placeholder' => 'Type something..', 'value' => $product->getName(), 'class' => 'form-control'));
$input->addValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_NotEmpty()));
$input->addDecorator($decoratorField);
$elements[] = $input;
// Add category field
$select = new Zend_Form_Element_Select('category_id', array('required' => true, 'label' => 'Category:', 'id' => 'category', 'class' => 'form-control'));
$categoryMapper = new Application_Model_CategoryMapper();
$categories = $categoryMapper->fetchAll();
foreach ($categories as $category) {
$select->addMultiOption($category->getId(), $category->getName());
}
// set selected option
$select->setValue($product->getCategoryId());
$select->addDecorator($decoratorField);
$elements[] = $select;
$currencyMapper = new Application_Model_CurrencyMapper();
$currency = $currencyMapper->getDefaultCurrency();
// Add Price field
$input = new Zend_Form_Element_Text('price', array('required' => true, 'label' => 'Price in ' . $currency->getCode() . ':', 'id' => 'price', 'placeholder' => 'Type something..', 'value' => number_format((double) $product->price, 2), 'class' => 'form-control', 'min' => self::MIN, 'max' => self::MAX, 'step' => 'any', 'type' => 'number'));
$min = new Zend_Validate_LessThan(self::MAX);
$max = new Zend_Validate_GreaterThan(self::MIN);
$input->addValidators(array(new Zend_Validate_Float(), $min, $max, new Zend_Validate_NotEmpty()));
$input->addDecorator($decoratorField);
$elements[] = $input;
if ($id) {
//Add File field
if ($product->file) {
$input = new Zend_Form_Element('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control', 'value' => $product->file));
$input->addDecorator(new My_Decorator_AnchoraFileForm());
$elements[] = $input;
} else {
$input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
$input->addDecorator($decoratorField);
$elements[] = $input;
}
//Add Image field
if ($product->image) {
$input = new Zend_Form_Element('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control', 'value' => $product->image));
$input->addDecorator(new My_Decorator_ImageForm());
$elements[] = $input;
} else {
$input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
$input->addDecorator($decoratorField);
$elements[] = $input;
}
} else {
//Add File field
$input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
$input->addDecorator($decoratorField);
$elements[] = $input;
//Add Image field
$input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
$input->addDecorator($decoratorField);
$elements[] = $input;
}
//Add Description field
$input = new Zend_Form_Element_Textarea('description', array('label' => 'Description:', 'id' => 'description', 'class' => 'form-control', 'value' => $product->description));
$input->addDecorator($decoratorField);
$elements[] = $input;
//Add Submit button
if (!$id) {
$input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-success', 'value' => 'Add New Product'));
} else {
$input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-info', 'value' => 'Update Product'));
}
$input->addDecorator($decoratorField);
$elements[] = $input;
$form->addElements($elements);
$form->addDisplayGroup(array('name', 'category_id', 'price', 'currency_id', 'file', 'image', 'description', 'submit'), 'displgrp', array('legend' => 'Add Products', 'decorators' => array('FormElements', 'Fieldset')));
return $form;
}