当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Form_Element_File::getValidator方法代码示例

本文整理汇总了PHP中Zend_Form_Element_File::getValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element_File::getValidator方法的具体用法?PHP Zend_Form_Element_File::getValidator怎么用?PHP Zend_Form_Element_File::getValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Form_Element_File的用法示例。


在下文中一共展示了Zend_Form_Element_File::getValidator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAutoInsertNotEmptyValidator

 /**
  * @group ZF-12210
  */
 public function testAutoInsertNotEmptyValidator()
 {
     $this->testElementShouldAllowSpecifyingAdapterUsingConcreteInstance();
     $this->element->setRequired(true);
     // Test before validation
     $this->assertNull($this->element->getValidator('NotEmpty'));
     // Test after validation
     $this->element->isValid('foo.jpg');
     $this->assertTrue($this->element->getValidator('NotEmpty') instanceof Zend_Validate_NotEmpty);
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:13,代码来源:FileTest.php

示例2: init

 /**
  *
  * Change network background
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/CustomBackground.phtml'))));
     // load settings
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $request_profile_id = $request->getParam('id', false);
     $profile = $Profiles->getProfileByField('id', $request_profile_id);
     if (Zend_Auth::getInstance()->getIdentity()->role == 'admin' && $request_profile_id || $request_profile_id && $Profiles->getProfile($profile->name, false, true)) {
         // admin or own group & page
         $profile_id = $request_profile_id;
     } else {
         // editing profile
         $profile_id = Zend_Auth::getInstance()->getIdentity()->id;
     }
     $all_meta = $ProfilesMeta->getMetaValues($profile_id);
     // fields
     $background_image = new Zend_Form_Element_File('background');
     $background_image->setDecorators(array('File', 'Errors'))->setLabel($this->translator->translate('Choose Picture (jpg, png or gif)'))->addValidator('Count', false, 1)->addValidator('Size', false, Zend_Registry::get('config')->get('max_file_upload_size'))->addValidator('Extension', false, 'jpg,jpeg,png,gif');
     $background_image->getValidator('Count')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_image->getValidator('Size')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_image->getValidator('Extension')->setMessage($this->translator->translate('File not allowed or too big'));
     $background_repeat = new Zend_Form_Element_Checkbox('background_repeat');
     $background_repeat->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_repeat']) && $all_meta['background_repeat'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Repeat background'))->setCheckedValue("1")->setUncheckedValue("0");
     $background_scroll = new Zend_Form_Element_Checkbox('background_scroll');
     $background_scroll->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_scroll']) && $all_meta['background_scroll'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Scroll background'))->setCheckedValue("1")->setUncheckedValue("0");
     $background_stretch = new Zend_Form_Element_Checkbox('background_stretch');
     $background_stretch->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_stretch']) && $all_meta['background_stretch'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Stretch background'))->setCheckedValue("1")->setUncheckedValue("0");
     $disable_image = new Zend_Form_Element_Checkbox('background_noimage');
     $disable_image->setDecorators(array('ViewHelper', 'Errors'))->setValue(isset($all_meta['background_noimage']) && $all_meta['background_noimage'] == 1 ? 1 : 0)->setLabel($this->translator->translate('Disable custom image'))->setCheckedValue("1")->setUncheckedValue("0");
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($background_image, $background_repeat, $background_scroll, $background_stretch, $disable_image, $submit));
     $this->postInit();
 }
开发者ID:georgepaul,项目名称:socialstrap,代码行数:44,代码来源:CustomBackground.php

示例3: array

error_reporting(E_ALL);
ini_set('display_errors', '1');
/**
 * @file form.php
 */
// Load Zend Framework
set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), __DIR__ . '/')));
// Create the auto loader so zend can load the rest automatically
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$form = new Zend_Form();
// Set form name, id, method and action
$form->setName('fileUpload')->setAttrib('id', 'fileUpload')->setMethod('post')->setAttrib('enctype', 'multipart/form-data')->setAction('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$file = new Zend_Form_Element_File('file');
$file->setLabel('File')->setRequired(true)->setValueDisabled(False)->addValidator('Extension', FALSE, 'jpg,jpeg')->addValidator('Size', false, array('min' => 20, 'max' => 20000000));
$file->getValidator('Extension')->setMessage('JPEGs only');
// Create text area for message
$message = new Zend_Form_Element_Textarea('message');
$message->setRequired(TRUE)->setAttrib('id', 'message')->addErrorMessage('Please specify a message');
// Create a submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit')->setAttrib('id', 'submit');
// Set the ViewScript decorator for the form and tell it which
// template file to use
$form->setDecorators(array(array('ViewScript', array('viewScript' => 'form-contact.tpl.php'))));
// Add the form elements AFTER the viewscript decorator has been set
$form->addElements(array($file, $message, $submit));
// Get rid of all element decorators except for ViewHelper to render
// the individual elements and Errors decorator to render the errors.
$form->setElementDecorators(array('ViewHelper', 'Errors'));
// The file element requires the File decorator instead of the
开发者ID:rmuktader,项目名称:zf-stand-alone-upload-form,代码行数:31,代码来源:form.php

示例4: addFile

 public function addFile($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $options = func_get_args();
     $options = \MUtil_Ra::pairs($options, 1);
     $options = $this->_mergeOptions($name, $options, self::DISPLAY_OPTIONS, self::FILE_OPTIONS, self::TEXT_OPTIONS);
     $filename = $this->_moveOption('filename', $options);
     $count = $this->_moveOption('count', $options);
     $size = $this->_moveOption('size', $options);
     $extension = $this->_moveOption('extension', $options);
     $element = new \Zend_Form_Element_File($name, $options);
     if ($filename) {
         $count = 1;
         // When
         // 1) an extension filter was defined,
         // 2) it concerns a single extension and
         // 3) $filename does not have an extension
         // then add the extension to the name.
         if ($extension && false === strpos($extension, ',') && false === strpos($name, '.')) {
             $filename .= '.' . $extension;
         }
         $element->addFilter(new \Zend_Filter_File_Rename(array('target' => $filename, 'overwrite' => true)));
     }
     if ($count) {
         $element->addValidator('Count', false, $count);
     }
     if ($size) {
         $element->addValidator('Size', false, $size);
     }
     if ($extension) {
         $element->addValidator('Extension', false, $extension);
         // Now set a custom validation message telling what extensions are allowed
         $validator = $element->getValidator('Extension');
         $validator->setMessage('Only %extension% files are accepted.', \Zend_Validate_File_Extension::FALSE_EXTENSION);
     }
     return $this->_addToForm($name, $element);
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:36,代码来源:FormBridge.php


注:本文中的Zend_Form_Element_File::getValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。