Phalcon表单
GitHub上的源码
-
命名空间
-
使用
InvalidArgumentException
Phalcon\Di\Di
Phalcon\Di\DiInterface
Phalcon\Filter\Validation\ValidatorInterface
Phalcon\Forms\Exception
Phalcon\Forms\Form
Phalcon\Html\Escaper
Phalcon\Html\TagFactory
Phalcon\Messages\MessageInterface
Phalcon\Messages\Messages
-
继承
-
实现
这是表单元素的基类
属性
/**
* @var array
*/
protected $attributes;
/**
* @var array
*/
protected $filters;
/**
* @var Form|null
*/
protected $form;
/**
* @var string|null
*/
protected $label;
/**
* @var string
*/
protected $method = inputText;
/**
* @var Messages
*/
protected $messages;
/**
* @var string
*/
protected $name;
/**
* @var array
*/
protected $options;
/**
* @var TagFactory|null
*/
protected $tagFactory;
/**
* @var array
*/
protected $validators;
/**
* @var mixed|null
*/
protected $value;
方法
public function __construct( string $name, array $attributes = [] );
构造函数 public function __toString(): string;
魔术方法__toString渲染不带属性的小部件 public function addFilter( string $filter ): ElementInterface;
向当前过滤器列表添加一个过滤器 public function addValidator( ValidatorInterface $validator ): ElementInterface;
向元素添加一个验证器 public function addValidators( array $validators, bool $merge = bool ): ElementInterface;
添加一组验证器 public function appendMessage( MessageInterface $message ): ElementInterface;
将消息追加到内部消息列表 public function clear(): ElementInterface;
清除元素到其默认值 public function getAttribute( string $attribute, mixed $defaultValue = null ): mixed;
返回存在的属性的值 public function getAttributes(): array;
返回元素的默认属性 public function getDefault(): mixed;
返回分配给元素的默认值 public function getFilters();
返回元素过滤器 public function getForm(): Form;
返回元素的父表单 public function getLabel(): string;
返回元素标签 public function getMessages(): Messages;
返回属于该元素的消息,元素需要附加到表单 public function getName(): string;
返回元素名称 public function getTagFactory(): TagFactory | null;
返回tagFactory;如果不存在则抛出异常 public function getUserOption( string $option, mixed $defaultValue = null ): mixed;
返回存在的选项的值 public function getUserOptions(): array;
返回元素的选项 public function getValidators(): ValidatorInterface[];
返回为元素注册的验证器 public function getValue(): mixed;
返回元素的值 public function hasMessages(): bool;
检查是否有消息附加到元素 public function label( array $attributes = [] ): string;
生成用于标记元素的HTML public function render( array $attributes = [] ): string;
渲染元素小部件返回HTML public function setAttribute( string $attribute, mixed $value ): ElementInterface;
为元素设置默认属性 public function setAttributes( array $attributes ): ElementInterface;
为元素设置默认属性 public function setDefault( mixed $value ): ElementInterface;
如果表单未使用实体或_Post中没有元素的值,则设置默认值 public function setFilters( mixed $filters ): ElementInterface;
设置元素过滤器 public function setForm( Form $form ): ElementInterface;
将父表单设置为元素 public function setLabel( string $label ): ElementInterface;
设置元素标签 public function setMessages( Messages $messages ): ElementInterface;
设置与元素相关的验证消息 public function setName( string $name ): ElementInterface;
设置元素名称 public function setTagFactory( TagFactory $tagFactory ): AbstractElement;
设置TagFactory public function setUserOption( string $option, mixed $value ): ElementInterface;
为元素设置选项 public function setUserOptions( array $options ): ElementInterface;
为元素设置选项 protected function getLocalTagFactory(): TagFactory;
返回tagFactory;如果不存在则抛出异常 GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=check]组件
属性
/**
* @var string
*/
protected $method = inputCheckbox;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=date]组件
属性
/**
* @var string
*/
protected $method = inputDate;
GitHub上的源码
-
命名空间
-
使用
Phalcon\Filter\Validation\ValidatorInterface
Phalcon\Forms\Form
Phalcon\Messages\MessageInterface
Phalcon\Messages\Messages
-
继承
-
实现
Phalcon\Forms\Element类的接口
方法
public function addFilter( string $filter ): ElementInterface;
向当前过滤器列表添加一个过滤器 public function addValidator( ValidatorInterface $validator ): ElementInterface;
向元素添加一个验证器 public function addValidators( array $validators, bool $merge = bool ): ElementInterface;
添加一组验证器 public function appendMessage( MessageInterface $message ): ElementInterface;
将消息追加到内部消息列表 public function clear(): ElementInterface;
将表单中的每个元素清除为其默认值 public function getAttribute( string $attribute, mixed $defaultValue = null ): mixed;
返回存在的属性的值 public function getAttributes(): array;
返回元素的默认属性 public function getDefault(): mixed;
返回分配给元素的默认值 public function getFilters();
返回元素的过滤器 public function getForm(): Form;
返回元素的父表单 public function getLabel(): string;
返回元素的标签 public function getMessages(): Messages;
返回属于该元素的消息,元素需要附加到表单 public function getName(): string;
返回元素的名称 public function getUserOption( string $option, mixed $defaultValue = null ): mixed;
返回存在的选项的值 public function getUserOptions(): array;
返回元素的选项 public function getValidators(): ValidatorInterface[];
返回为元素注册的验证器 public function getValue(): mixed;
返回元素的值 public function hasMessages(): bool;
检查是否有消息附加到元素 public function label(): string;
生成用于标记元素的HTML public function render( array $attributes = [] ): string;
渲染元素小部件 public function setAttribute( string $attribute, mixed $value ): ElementInterface;
为元素设置默认属性 public function setAttributes( array $attributes ): ElementInterface;
为元素设置默认属性 public function setDefault( mixed $value ): ElementInterface;
如果表单未使用实体或_Post中没有元素的值,则设置默认值 public function setFilters( mixed $filters ): ElementInterface;
设置元素的过滤器 public function setForm( Form $form ): ElementInterface;
将父表单设置为元素 public function setLabel( string $label ): ElementInterface;
设置元素标签 public function setMessages( Messages $messages ): ElementInterface;
设置与元素相关的验证消息 public function setName( string $name ): ElementInterface;
设置元素的名称 public function setUserOption( string $option, mixed $value ): ElementInterface;
为元素设置选项 public function setUserOptions( array $options ): ElementInterface;
为元素设置选项 GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=email]组件
属性
/**
* @var string
*/
protected $method = inputEmail;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=file]组件
属性
/**
* @var string
*/
protected $method = inputFile;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=hidden]组件
属性
/**
* @var string
*/
protected $method = inputHidden;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=number]组件
属性
/**
* @var string
*/
protected $method = inputNumeric;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=password]组件
属性
/**
* @var string
*/
protected $method = inputPassword;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=radio]组件
属性
/**
* @var string
*/
protected $method = inputRadio;
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的选择(选择)组件
属性
/**
* @var object|array|null
*/
protected $optionsValues;
方法
public function __construct( string $name, mixed $options = null, array $attributes = [] );
构造函数 public function addOption( mixed $option ): ElementInterface;
向当前选项添加一个选项 public function getOptions();
返回选项的选择 public function render( array $attributes = [] ): string;
渲染元素小部件返回HTML public function setOptions( mixed $options ): ElementInterface;
设置选项的选择 protected function prepareAttributes( array $attributes = [] ): array;
根据元素参数返回为Phalcon\Html\TagFactory助手准备的属性数组 GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=submit]组件
属性
/**
* @var string
*/
protected $method = inputSubmit;
表单\元素\Text
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的INPUT[type=text]组件
表单\元素\TextArea
GitHub上的源码
-
命名空间
-
使用
-
继承
AbstractElement
-
实现
表单的TEXTAREA组件
属性
/**
* @var string
*/
protected $method = inputTextarea;
GitHub上的源码
在Phalcon\Forms中抛出的异常将使用此类
GitHub上的源码
-
命名空间
-
使用
Countable
Iterator
Phalcon\Di\DiInterface
Phalcon\Di\Injectable
Phalcon\Filter\FilterInterface
Phalcon\Filter\Validation
Phalcon\Filter\Validation\ValidationInterface
Phalcon\Forms\Element\ElementInterface
Phalcon\Html\Attributes
Phalcon\Html\Attributes\AttributesInterface
Phalcon\Html\TagFactory
Phalcon\Messages\Messages
Phalcon\Tag
-
继承
Injectable
-
实现
AttributesInterface
Countable
Iterator
此组件允许使用面向对象的接口构建表单
属性
/**
* @var AttributesInterface|null
*/
protected $attributes;
/**
* @var array
*/
protected $data;
/**
* @var array
*/
protected $filteredData;
/**
* @var array
*/
protected $elements;
/**
* @var array
*/
protected $elementsIndexed;
/**
* @var object|null
*/
protected $entity;
/**
* @var Messages|array|null
*/
protected $messages;
/**
* @var int
*/
protected $position = ;
/**
* @var array
*/
protected $options;
/**
* @var TagFactory|null
*/
protected $tagFactory;
/**
* @var ValidationInterface|null
*/
protected $validation;
/**
* @var array
*/
protected $whitelist;
方法
public function __construct( mixed $entity = null, array $userOptions = [] );
Phalcon\Forms\Form构造函数 public function add( ElementInterface $element, string $position = null, bool $type = null ): Form;
向表单添加元素 public function bind( array $data, mixed $entity = null, array $whitelist = [] ): Form;
将数据绑定到实体 public function clear( mixed $fields = null ): Form;
将表单中的每个元素清除为其默认值 public function count(): int;
返回表单中的元素数量 public function current(): mixed;
返回迭代器中的当前元素 public function get( string $name ): ElementInterface;
根据名称返回添加到表单的元素 public function getAction(): string;
返回表单的动作 public function getAttributes(): Attributes;
获取表单属性集合 public function getElements(): ElementInterface[];
返回添加到表单的表单元素 public function getEntity();
返回与模型相关的实体 public function getFilteredValue( string $name ): mixed | null;
从内部过滤数据获取值或调用getValue(name) public function getLabel( string $name ): string;
返回元素的标签 public function getMessages(): Messages | array;
返回在验证期间生成的消息 if ($form->isValid($_POST) == false) {
$messages = $form->getMessages();
foreach ($messages as $message) {
echo $message, "<br>";
}
}
public function getMessagesFor( string $name ): Messages;
返回为特定元素生成的消息 public function getTagFactory(): TagFactory | null;
返回tagFactory对象 public function getUserOption( string $option, mixed $defaultValue = null ): mixed;
返回存在的选项的值 public function getUserOptions(): array;
返回元素的选项 public function getValidation(): ValidationInterface | null;
return ValidationInterface|null public function getValue( string $name ): mixed | null;
从内部相关实体获取值或从默认值获取值 public function getWhitelist(): array;
返回数组 public function has( string $name ): bool;
检查表单是否包含一个元素 public function hasMessagesFor( string $name ): bool;
检查是否为特定元素生成了消息 public function isValid( mixed $data = null, mixed $entity = null, array $whitelist = [] ): bool;
验证表单 public function key(): int;
返回迭代器中的当前位置/键 public function label( string $name, array $attributes = [] ): string;
生成添加到表单中的元素的标签(包括HTML) public function next(): void;
将内部迭代指针移动到下一个位置 public function remove( string $name ): bool;
从表单中移除一个元素 public function render( string $name, array $attributes = [] ): string;
渲染表单中的特定项 public function rewind(): void;
重绕内部迭代器 public function setAction( string $action ): Form;
设置表单的操作 public function setAttributes( Attributes $attributes ): AttributesInterface;
设置表单属性集合 public function setEntity( mixed $entity ): Form;
设置与模型相关的实体 public function setTagFactory( TagFactory $tagFactory ): Form;
为表单设置tagFactory public function setUserOption( string $option, mixed $value ): Form;
为表单设置一个选项 public function setUserOptions( array $options ): Form;
为元素设置选项 public function setValidation( ValidationInterface $validation ): Form;
设置默认验证 public function setWhitelist( array $whitelist ): Form;
设置默认白名单 public function valid(): bool;
检查迭代器中的当前元素是否有效 GitHub上的源码
表单管理器
属性
/**
* @var array
*/
protected $forms;
方法
public function create( string $name, mixed $entity = null ): Form;
创建一个表单并将其注册到表单管理器中 public function get( string $name ): Form;
根据名称返回一个表单 public function has( string $name ): bool;
检查表单是否已注册到表单管理器中 public function set( string $name, Form $form ): Manager;
在表单管理器中注册一个表单