當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Form::setDescription方法代碼示例

本文整理匯總了PHP中Zend_Form::setDescription方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Form::setDescription方法的具體用法?PHP Zend_Form::setDescription怎麽用?PHP Zend_Form::setDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Form的用法示例。


在下文中一共展示了Zend_Form::setDescription方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCanSetDescription

 public function testCanSetDescription()
 {
     $this->testDescriptionInitiallyNull();
     $description = "This is a description";
     $this->form->setDescription($description);
     $this->assertEquals($description, $this->form->getDescription());
 }
開發者ID:vicfryzel,項目名稱:zf,代碼行數:7,代碼來源:FormTest.php

示例2: getForm


//.........這裏部分代碼省略.........
         }
         $formDef = $this->getFormDefinition($form);
         if (!array_key_exists('type', $formDef['element'])) {
             $formDef = $formDef['element'];
         }
         $elementStack = array();
         foreach ($formDef as $elementDef) {
             /**
              * @var $element Zend_Form_Element|Zend_Form_Element_Select
              */
             $className = 'Zend_Form_Element_' . ucfirst($elementDef['type']);
             $element = new $className($elementDef['name'], array('label' => isset($elementDef['label']) ? $elementDef['label'] : '', 'value' => isset($elementDef['val']) ? $elementDef['val'] : '', 'helper' => 'form' . ucfirst($elementDef['type']), 'required' => isset($elementDef['required']) ? (int) $elementDef['required'] : 0));
             if ($elementDef['type'] == 'select') {
                 if (isset($elementDef['option'])) {
                     foreach ($elementDef['option'] as $option) {
                         $element->addMultiOptions(array($option['val'] => $option['label']));
                         if (isset($option['selected'])) {
                             $element->setValue($option['val']);
                         }
                     }
                 } elseif (isset($elementDef['callback'])) {
                     if (isset($elementDef['callback']['function'])) {
                         $options = call_user_func_array($elementDef['callback']['function'], (array) isset($elementDef['callback']['argument']) ? $elementDef['callback']['argument'] : array());
                         if ($elementDef['callback']['function'] == 'range') {
                             $options = array_combine($options, $options);
                         }
                         $element->addMultiOptions($options);
                         if (isset($elementDef['callback']['selected'])) {
                             $element->setValue($elementDef['callback']['selected']);
                         }
                     } else {
                         require_once 'iPMS/Widgets/Exception.php';
                         throw new iPMS_Widgets_Exception('Unable to generate element options from callback: function name not found');
                     }
                 } else {
                     require_once 'iPMS/Widgets/Exception.php';
                     throw new iPMS_Widgets_Exception('All select elements must have options');
                 }
             }
             if (isset($elementDef['id'])) {
                 // Optional CSS id for element
                 $element->setAttrib('id', $elementDef['id']);
             }
             if (isset($elementDef['class'])) {
                 // Optional CSS class for element
                 $element->setAttrib('class', $elementDef['class']);
             }
             if (isset($elementDef['filter'])) {
                 // Optional filter(s) for element
                 $element->addFilters((array) $elementDef['filter']);
             }
             // Optional validator for element
             if (isset($elementDef['validator'])) {
                 // Optional validator for element
                 $element->addValidators((array) $elementDef['validator']);
             }
             $elementStack[] = $element;
         }
         // Creating new form instance
         $formInstance = new Zend_Form();
         $formInstance->setName($form)->setElementsBelongTo($form)->addElements($elementStack);
         // Optional description for the Form
         if (isset($formDef['description'])) {
             $formInstance->setDescription($formDef['description'])->addDecorator('Description', array('placement' => 'prepend'));
         }
     } elseif (is_array($form) && isset($form['clasname'])) {
         // Form generated from specific class
         $className = $form['clasname'];
         if (isset($this->_formInstances[$className])) {
             return $this->_formInstances[$className];
         }
         if (!class_exists($className)) {
             require_once 'Zend/Loader.php';
             Zend_Loader::loadClass($className, isset($form['path']) ? isset($form['path']) : null);
         }
         $formInstance = new $className();
         if (!$formInstance instanceof Zend_Form) {
             require_once 'iPMS/Widgets/Exception.php';
             throw new iPMS_Widgets_Exception(sprintf('Invalid argument: Detected class "%s", which is not an instance of Zend_Form', $className));
         }
     } else {
         require_once 'iPMS/Widgets/Exception.php';
         throw new iPMS_Widgets_Exception('Invalid argument $form');
     }
     // Common treatment
     if ($form !== 'dashboard') {
         $hidden = new Zend_Form_Element_Hidden('widgetUpdate');
         $hidden->setValue($this . '_' . $this->_id)->setRequired(true);
         $hidden->getDecorator('HtmlTag')->setOption('class', 'hidden');
         $hidden->getDecorator('Label')->setOption('tagClass', 'hidden');
         $formInstance->addElement($hidden);
     }
     // Add a submit element if it doesn't already defined
     if (null === $formInstance->getElement('submit')) {
         $submit = new Zend_Form_Element_Submit('submit');
         $submit->setLabel('submit');
         $formInstance->addElement($submit);
     }
     return $this->_formInstances[isset($className) ? $className : $form] = $formInstance;
 }
開發者ID:nuxwin,項目名稱:i-PMS,代碼行數:101,代碼來源:Widget.php

示例3: array

<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/path/to/zend/library');
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$request = new Zend_Controller_Request_Http();
$view = new Zend_View();
/**
 * Example showing usage of array notation using setElementsBelongTo
 * on the form level, for shipping/billing addresses.
 */
$form = new Zend_Form();
$form->setView($view);
$form->addDecorator('Description', array('escape' => false, 'placement' => 'PREPEND'));
$form->setDescription('<h3>Using setElementsBelongTo</h3>');
$form->setElementsBelongTo('shipping');
$form->addElement('text', 'recipient', array('label' => 'Ship to', 'required' => true));
$form->addElement('text', 'address', array('label' => 'Address', 'required' => true));
$form->addElement('submit', 'submit', array('label' => 'Submit'));
if ($request->isPost()) {
    if ($form->isValid($request->getPost())) {
        echo 'Order placed, Thank you!';
    } else {
        echo 'You have errors in your form, please check';
    }
}
echo $form->render();
開發者ID:Tony133,項目名稱:zf-web,代碼行數:27,代碼來源:Zend_Form_elementsBelongTo.php

示例4: array

<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/path/to/zend/library');
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$request = new Zend_Controller_Request_Http();
$view = new Zend_View();
/**
 * Example showing usage of array notation using belongsTo
 * for shipping/billing addresses.
 */
$form = new Zend_Form();
$form->setView($view);
$form->addDecorator('Description', array('escape' => false, 'placement' => 'PREPEND'));
$form->setDescription('<h3>Using belongsTo</h3>');
$form->addElement('text', 'recipient', array('label' => 'Ship to', 'required' => true, 'belongsTo' => 'shipping'));
$form->addElement('text', 'address1', array('label' => 'Address 1', 'required' => true, 'belongsTo' => 'shipping[addresses]'));
$form->addElement('submit', 'submit', array('label' => 'Submit'));
if ($request->isPost()) {
    if ($form->isValid($request->getPost())) {
        echo 'Order placed, Thank you!';
    } else {
        echo 'You have errors in your form, please check';
    }
}
echo $form->render();
開發者ID:Tony133,項目名稱:zf-web,代碼行數:26,代碼來源:Zend_Form_belongsTo.php


注:本文中的Zend_Form::setDescription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。