0

それが Object\Model の私のモデル SiteDesign.php です:

namespace Object\Model;

use Zend\Validator\StringLength;
use Zend\Validator\NotEmpty;
use Zend\Validator\File\Size;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class SiteDesign {

public $logo_filename;
public $background_image;
public $background_color;

public function exchangeArray($data) {
    $this->logo_filename = (isset($data['logo_filename'])) ? $data['logo_filename'] : null;
    $this->background_image = (isset($data['background_image'])) ? $data['background_image'] : null;
    $this->background_color = (isset($data['background_color'])) ? $data['background_color'] : null;
}

public function setInputFilter(InputFilterInterface $inputFilter) {
    throw new \Exception('Not used');
}

public function getInputFilter() {
    if (!$this->inputFilter) {
        $inputFilter = new InputFilter();

        $factory = new InputFactory();

        $inputFilter->add($factory->createInput(array(
                    'name' => 'logo_filename',
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'FilesSize',
                            'options' => array(
                                'max' => 4 * 1024,
                                'messages' => array(
                                    Size::TOO_BIG => 'Размерът на логото не може да надвишава 5MB.',
                                ),
                            ),
                        ),
                    ),
                )));

        $inputFilter->add($factory->createInput(array(
                    'name' => 'background_image',
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'FilesSize',
                            'options' => array(
                                'max' => 4 * 1024,
                                'messages' => array(
                                    Size::TOO_BIG => 'Размерът на изображението за фон не може да надвишава 5MB.',
                                ),
                            ),
                        ),
                    ),
                )));

        $inputFilter->add($factory->createInput(array(
                    'name' => 'background_color',
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                    ),
                )));

        $this->inputFilter = $inputFilter;
    }

    return $this->inputFilter;
}

}

しかし、エラーメッセージがあります:

Zend\ServiceManager\ServiceManager::get は、FilesSize のインスタンスを取得または作成できませんでした

ファクトリを使用してモデルで FilesSize バリデータを直接定義することは可能ですか? そして、これは正しい方法ですか?前もって感謝します。

4

1 に答える 1

0

(名前でバリデーターをインスタンス化する役割を果たします)現在Zend\Validator\ValidatorPluginManager、正しい名前は `" FileSize "です(そこに"が多すぎます)。

于 2013-02-18T09:12:36.487 に答える