nicolas-brousse / paris-form-helper
Paris ORM 的表单助手,灵感来源于 ActiveView::Helpers::FormHelper
Requires
- php: >=5.2.0
Suggests
- j4mie/paris: A lightweight Active Record implementation for PHP5, built on top of Idiorm
This package is not auto-updated.
Last update: 2024-09-24 02:27:46 UTC
README
Paris ORM 的表单助手,灵感来源于 ActiveView::Helpers::FormHelper。
它可以不依赖 Paris 使用。
示例
A Paris Model
<?php /** * Post table columns: * - id * - title * - content * - author * - is_publish */ class Post extends Model {}
视图示例
<?php $post = Model::factory('Post')->create(); ?> ... <?php $form = Helpers_Form::form_for($post, '/posts/create', array('html' =>array('class' => 'form'))) ?> <?= $form->label('title') ?><br /> <?= $form->text_field('title') ?> <?= $form->label('content') ?><br /> <?= $form->text_area('content', array('cols' => 50, 'rows' => 4)) ?> <?= $form->label('author') ?><br /> <?= $form->text_area('author', array('class' => 'author-input')) ?> <?= $form->label('is_publish') ?><br /> <?= $form->text_area('is_publish', array('check_value' => 'yes', 'uncheck_value' => 'no')) ?> <?php Helpers_Form::end_form_for() ?>
如何使用它?
开始表单
要开始表单,请使用 Helpers_Form::form_for($model, $form_action, array $options)
。
$model
: 用于表单的模型。因此,表单值将自动设置。对于独立表单,它可以设置为 null。
$form_action
: 发送数据的 URL。
$options
: 表单选项。选项包括
- method: 精确表单方法(post|get)。注意:如果您使用 Paris Model,则方法将自动设置为 post(如果模型是新的)和 put(用于编辑)。
- html: 向
<form />
标签添加属性。并返回表单实例。这是访问表单助手方法的必要条件。
要关闭表单,请使用 Helpers_Form::end_form_for()
来打印它。
标签
$form->label(string $name [ string $label, [, array $attributes [, array $options ]]])
输入
输入列表: 复选框 - 电子邮件 - 隐藏 - 密码 - 文本
隐藏
文本
$form->text_field(string $name [, array $attributes [, array $options ]])
电子邮件
$form->email_field(string $name [, array $attributes [, array $options ]])
密码
$form->password_field(string $name [, array $attributes [, array $options ]])
复选框
$form->checkbox(string $name [, array $attributes [, array $options ]])
文本区域
$form->textarea(string $name [, array $attributes [, array $options ]])
提交
$form->submit(string $label [, array $attributes ])