cakephp/form
最新稳定版本:5.4.0-RC1
Composer 安装命令:
composer require cakephp/form
包简介
CakePHP Form library
README 文档
README
CakePHP Form Library
Form abstraction used to create forms not tied to ORM backed models, or to other permanent datastores. Ideal for implementing forms on top of API services, or contact forms.
Usage
use Cake\Form\Form; use Cake\Form\Schema; use Cake\Validation\Validator; class ContactForm extends Form { protected function _buildSchema(Schema $schema) { return $schema->addField('name', 'string') ->addField('email', ['type' => 'string']) ->addField('body', ['type' => 'text']); } public function validationDefault(Validator $validator) { return $validator->add('name', 'length', [ 'rule' => ['minLength', 10], 'message' => 'A name is required' ])->add('email', 'format', [ 'rule' => 'email', 'message' => 'A valid email address is required', ]); } protected function _execute(array $data) { // Send an email. return true; } }
In the above example we see the 3 hook methods that forms provide:
_buildSchema()is used to define the schema data. You can define field type, length, and precision.validationDefault()Gets aCake\Validation\Validatorinstance that you can attach validators to._execute()lets you define the behavior you want to happen whenexecute()is called and the data is valid.
You can always define additional public methods as you need as well.
$contact = new ContactForm(); $success = $contact->execute($data); $errors = $contact->getErrors();
Documentation
Please make sure you check the official documentation
统计信息
- 总下载量: 1.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-28