本文整理汇总了PHP中Fieldset::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Fieldset::instance方法的具体用法?PHP Fieldset::instance怎么用?PHP Fieldset::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fieldset
的用法示例。
在下文中一共展示了Fieldset::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($obj, $fieldset = null)
{
static $_generated = array();
$class = is_object($obj) ? get_class($obj) : $obj;
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::factory($class);
}
}
!array_key_exists($class, $_generated) and $_generated[$class] = array();
if (in_array($fieldset, $_generated[$class], true)) {
return $fieldset;
}
$_generated[$class][] = $fieldset;
$fieldset->validation()->add_callable($obj);
$properties = is_object($obj) ? $obj->properties() : $class::properties();
foreach ($properties as $p => $settings) {
$field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
if (empty($settings['validation'])) {
continue;
} else {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例2: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($class, $fieldset = null)
{
$properties = $class::properties();
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::factory($class);
}
}
foreach ($properties as $p => $settings) {
$field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
if (empty($settings['validation'])) {
continue;
} else {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例3: get_form
private function get_form($type = 0)
{
$form = Fieldset::instance();
if (count($form->field()) > 0) {
return $form;
}
switch ($type) {
case SettingType::PASSWORD:
$form->add("mail_address_new", "新しいメールアドレス");
$form->add("mail_address_new_confirm", "新しいメールアドレス(確認)");
$form->add("password", "現在のパスワード")->add_rule("required");
$form->add("password_new", "新しいパスワード")->add_rule("required")->add_rule("min_length", 4)->add_rule("max_length", 30)->add_rule("valid_string", array("alpha", "numeric"));
$form->add("password_new_confirm", "新しいパスワード(確認)")->add_rule("required")->add_rule("match_field", "password_new");
break;
case SettingType::MAILADDRESS:
$form->add("mail_address_new", "新しいメールアドレス")->add_rule("required")->add_rule("valid_email");
$form->add("mail_address_new_confirm", "新しいメールアドレス(確認)");
$form->add("password", "現在のパスワード");
$form->add("password_new", "新しいパスワード");
$form->add("password_new_confirm", "新しいパスワード(確認)");
break;
default:
break;
}
return $form;
}
示例4: get_form
private function get_form()
{
$form = Fieldset::instance();
if (count($form->field()) > 0) {
return $form;
}
$form->add('email', 'メールアドレス')->add_rule('required')->add_rule('max_length', 30)->add_rule('valid_email');
$form->add('password', 'パスワード')->add_rule('required')->add_rule('max_length', 30);
$form->add('remember', 'パスワードを保存する')->add_rule('match_value', '1');
return $form;
}
示例5: action_password
/**
* Mmeber setting password
*
* @access public
* @return Response
*/
public function action_password()
{
if (!($form = Fieldset::instance('setting_password'))) {
$form = $this->form_setting_password();
}
if (Input::method() === 'POST') {
$form->repopulate();
}
$this->set_title_and_breadcrumbs(term('site.password', 'form.update'), array('member/setting/' => term('site.setting', 'form.update')), $this->u);
$this->template->content = View::forge('_parts/setting/password');
$this->template->content->set_safe('html_form', $form->build('member/setting/change_password'));
}
示例6: action_index
/**
* Mmeber leave
*
* @access public
* @return Response
*/
public function action_index()
{
if (!($form = Fieldset::instance('leave'))) {
$form = $this->form_leave();
}
if (Input::method() === 'POST') {
$form->repopulate();
}
$this->set_title_and_breadcrumbs(term('site.left'), array('member/setting' => term('site.setting', 'form.update')), $this->u);
$this->template->content = View::forge('member/leave/index');
$this->template->content->set_safe('html_form', $form->build('member/leave/confirm'));
// form の action に入る
}
示例7: action_resend_password
/**
* Resend password
*
* @access public
* @return Response
*/
public function action_resend_password()
{
if (!($form = Fieldset::instance('resend_password'))) {
$form = $this->form_resend_password();
}
if (Input::method() === 'POST') {
$form->repopulate();
}
$this->set_title_and_breadcrumbs(term('site.password') . 'の再設定');
$this->template->content = View::forge('member/recover/resend_password');
$this->template->content->set_safe('html_form', $form->build('member/recover/send_reset_password_mail'));
// form の action に入る
}
示例8: get_form
private function get_form()
{
$form = Fieldset::instance();
if (count($form->field()) > 0) {
return $form;
}
$form->add('ope');
$form->add('id');
$form->add('name', 'お名前')->add_rule('required')->add_rule('max_length', 50);
$form->add('email', 'メールアドレス')->add_rule('required');
$form->add('status', 'ステータス')->add_rule('required');
return $form;
}
示例9: get_form
private function get_form()
{
$form = Fieldset::instance();
if (count($form->field()) > 0) {
return $form;
}
$form->add("contact_type", "お問い合わせ項目")->add_rule("required")->add_rule("match_pattern", "/" . implode("|", array_keys($this->contactType)) . "/");
$form->add("name", "お名前")->add_rule("required")->add_rule("max_length", 50);
$form->add("name_kana", "お名前(フリガナ)")->add_rule("required")->add_rule("max_length", 50)->add_rule("valid_katakana");
$form->add("tel", "電話番号")->add_rule("required")->add_rule("valid_tel");
$form->add("mail_address", "メールアドレス")->add_rule("required")->add_rule("valid_email");
$form->add("mail_address_confirm", "メールアドレス(確認)")->add_rule("required")->add_rule("match_field", "mail_address");
$form->add("contact_detail", "お問い合わせ内容")->add_rule("required")->add_rule("max_length", 1000);
$form->add("agree", "同意")->add_rule("match_value", 1);
return $form;
}
示例10: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($obj, $fieldset = null)
{
static $_generated = array();
$class = is_object($obj) ? get_class($obj) : $obj;
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::forge($class);
}
}
!array_key_exists($class, $_generated) and $_generated[$class] = array();
if (in_array($fieldset, $_generated[$class], true)) {
return $fieldset;
}
$_generated[$class][] = $fieldset;
$primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key();
$properties = is_object($obj) ? $obj->properties() : $class::properties();
foreach ($properties as $p => $settings) {
if (\Arr::get($settings, 'skip', in_array($p, $primary_keys))) {
continue;
}
if (isset($settings['form']['options'])) {
foreach ($settings['form']['options'] as $key => $value) {
is_array($value) or $settings['form']['options'][$key] = \Lang::get($value, array(), false) ?: $value;
}
}
// field attributes can be passed in form key
$attributes = isset($settings['form']) ? $settings['form'] : array();
// label is either set in property setting, as part of form attributes or defaults to fieldname
$label = isset($settings['label']) ? $settings['label'] : (isset($attributes['label']) ? $attributes['label'] : $p);
$label = \Lang::get($label, array(), false) ?: $label;
// create the field and add validation rules
$field = $fieldset->add($p, $label, $attributes);
if (!empty($settings['validation'])) {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例11: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($obj, $fieldset = null)
{
static $_generated = array();
$class = is_object($obj) ? get_class($obj) : $obj;
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::forge($class);
}
}
!array_key_exists($class, $_generated) and $_generated[$class] = array();
if (in_array($fieldset, $_generated[$class], true)) {
return $fieldset;
}
$_generated[$class][] = $fieldset;
$primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key();
$properties = is_object($obj) ? $obj->properties() : $class::properties();
foreach ($properties as $p => $settings) {
if (in_array($p, $primary_keys)) {
continue;
}
if (isset($settings['form']['options'])) {
foreach ($settings['form']['options'] as $key => $value) {
$settings['form']['options'][$key] = \Lang::line($value) ?: $value;
}
}
$label = isset($settings['label']) ? $settings['label'] : $p;
$attributes = isset($settings['form']) ? $settings['form'] : array();
$field = $fieldset->add($p, $label, $attributes);
if (!empty($settings['validation'])) {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例12: action_email
/**
* Admin setting email
*
* @access public
* @return Response
*/
public function action_email()
{
if (!($form = \Fieldset::instance('setting_email'))) {
$form = $this->form_setting_email();
}
if (\Input::method() === 'POST') {
$form->repopulate();
}
$this->set_title_and_breadcrumbs(term('site.email', 'form.update'), array('admin/setting' => term('site.setting', 'form.update')));
$this->template->content = \View::forge('_parts/setting/email');
$this->template->content->set_safe('html_form', $form->build('admin/setting/change_email'));
}
示例13: instance
public static function instance($name = null)
{
$fieldset = \Fieldset::instance($name);
return $fieldset === false ? false : $fieldset->validation();
}
示例14: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param \Fieldset|null
* @return \Fieldset
*/
public static function set_fields($obj, $fieldset = null)
{
static $_generated = array();
static $_tabular_rows = array();
$class = is_object($obj) ? get_class($obj) : $obj;
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::forge($class);
}
}
// is our parent fieldset a tabular form set?
$tabular_form = is_object($fieldset->parent()) ? $fieldset->parent()->get_tabular_form() : false;
// don't cache tabular form fieldsets
if (!$tabular_form) {
!array_key_exists($class, $_generated) and $_generated[$class] = array();
if (in_array($fieldset, $_generated[$class], true)) {
return $fieldset;
}
$_generated[$class][] = $fieldset;
}
$primary_keys = is_object($obj) ? $obj->primary_key() : $class::primary_key();
$primary_key = count($primary_keys) === 1 ? reset($primary_keys) : false;
$properties = is_object($obj) ? $obj->properties() : $class::properties();
if ($tabular_form and $primary_key and !is_object($obj)) {
isset($_tabular_rows[$class]) or $_tabular_rows[$class] = 0;
}
foreach ($properties as $p => $settings) {
if (\Arr::get($settings, 'skip', in_array($p, $primary_keys))) {
continue;
}
if (isset($settings['form']['options'])) {
foreach ($settings['form']['options'] as $key => $value) {
is_array($value) or $settings['form']['options'][$key] = \Lang::get($value, array(), false) ?: $value;
}
}
// field attributes can be passed in form key
$attributes = isset($settings['form']) ? $settings['form'] : array();
// label is either set in property setting, as part of form attributes or defaults to fieldname
$label = isset($settings['label']) ? $settings['label'] : (isset($attributes['label']) ? $attributes['label'] : $p);
$label = \Lang::get($label, array(), false) ?: $label;
// change the fieldname and label for tabular form fieldset children
if ($tabular_form and $primary_key) {
if (is_object($obj)) {
$p = $tabular_form . '[' . $obj->{$primary_key} . '][' . $p . ']';
} else {
$p = $tabular_form . '_new[' . $_tabular_rows[$class] . '][' . $p . ']';
}
$label = '';
}
// create the field and add validation rules
$field = $fieldset->add($p, $label, $attributes);
if (!empty($settings['validation'])) {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_fuel_func_array(array($field, 'add_rule'), $args);
}
}
}
// increase the row counter for tabular row fieldsets
if ($tabular_form and $primary_key and !is_object($obj)) {
$_tabular_rows[$class]++;
}
return $fieldset;
}
示例15: action_confirm_signup
/**
* Execute confirm signup
*
* @access public
* @return Response
*/
public function action_confirm_signup()
{
Util_security::check_method('POST');
Util_security::check_csrf();
if (!($form = Fieldset::instance('confirm_signup'))) {
$form = $this->get_form_signup_confirm();
}
$val = $form->validation();
$val->fieldset()->field('email')->delete_rule('unique');
$redirect_uri = conf('login_uri.site');
$success_message = '仮登録が完了しました。受信したメール内に記載された URL より本登録を完了してください。';
$error_message = '';
$is_transaction_rollback = false;
try {
if (!$val->run()) {
throw new \FuelException($val->show_errors());
}
$post = $val->validated();
if (Model_MemberAuth::get4email($post['email'])) {
if (conf('member.register.email.hideUniqueCheck')) {
Session::set_flash('message', $success_message);
Response::redirect($redirect_uri);
}
throw new FuelException('その' . term('site.email') . 'は登録できません。');
}
DB::start_transaction();
$token = Model_MemberPre::save_with_token($post['email'], $post['password']);
DB::commit_transaction();
$mail = new Site_Mail('memberSignup');
$mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token)));
Session::set_flash('message', $success_message);
Response::redirect($redirect_uri);
} catch (EmailValidationFailedException $e) {
Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error');
$error_message = 'メール送信エラー';
} catch (EmailSendingFailedException $e) {
Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error');
$error_message = 'メール送信エラー';
} catch (\Database_Exception $e) {
$is_transaction_rollback = true;
$error_message = \Site_Controller::get_error_message($e, true);
} catch (FuelException $e) {
$is_transaction_rollback = true;
$error_message = $e->getMessage();
}
if ($is_transaction_rollback && DB::in_transaction()) {
DB::rollback_transaction();
}
Session::set_flash('error', $error_message);
$this->action_signup();
}