当前位置: 首页>>代码示例>>PHP>>正文


PHP Formo::form方法代码示例

本文整理汇总了PHP中Formo::form方法的典型用法代码示例。如果您正苦于以下问题:PHP Formo::form方法的具体用法?PHP Formo::form怎么用?PHP Formo::form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Formo的用法示例。


在下文中一共展示了Formo::form方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_form

 /**
  * @dataProvider provider_form
  */
 public function test_form(array $args, array $array)
 {
     $expected = TRUE;
     $result = TRUE;
     $form = Formo::form($args);
     foreach ($array as $key => $value) {
         if ($form->get($key) !== $value) {
             $result = FALSE;
         }
     }
     $this->assertSame($expected, $result);
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:15,代码来源:FormoTest.php

示例2: action_update

 public function action_update()
 {
     $element = ORM::Factory($this->_orm_model, $_GET['id']);
     $form = Formo::form()->orm('load', $element);
     $form->add('update', 'submit', 'Save');
     if ($form->load($_POST)->validate()) {
         if ($this->_update_passed($form, $element)) {
             $element->save();
             $form->orm('save_rel', $element);
             $this->request->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
         }
     } else {
         $this->_update_failed($form, $element);
     }
     return $this->render('update', array('form' => $form));
 }
开发者ID:kanikaN,项目名称:qload,代码行数:16,代码来源:abstract.php

示例3: get_form

 /**
  * Create a form from an ORM Model
  * You can optionally pass a form to have fields added to
  * 
  * @access public
  * @param array $fields (default: NULL)
  * @param Formo $form (default: NULL)
  * @return Formo
  */
 public function get_form(array $fields, Formo $form = NULL)
 {
     if (Arr::get($fields, 0) === '*') {
         // Get the default set of fields
         // By default, load all the fields
         $arr = array_keys($this->as_array());
         if (count($fields) > 1) {
             // If other fields are listed, add them to the array
             // this allows for something like ['*', 'foo', 'bar']
             array_shift($fields);
             $arr = Arr::merge($arr, $fields);
         }
         // Set the fields to the combined array
         $fields = $arr;
     }
     if ($form === NULL) {
         // If a form object wasn't passed as the second argument,
         // create that form object here
         $alias = $this->_formo_alias ?: $this->_object_name;
         $form = Formo::form(['alias' => $alias]);
     }
     // Set up foreign keys map for easy access
     $this->_find_foreign_keys();
     // Now we iterate through each field
     foreach ($fields as $key => $field_name) {
         if (is_array($field_name)) {
             $method = 'formo_' . $key;
             if (strpos($method, '.') !== FALSE) {
                 $method = str_replace('.', '_', $method);
             }
             $rs = $this->{$method}();
             if ($rs instanceof Database_Result) {
                 $model = $rs->current();
                 $blueprint = $model->get_form($field_name)->set('alias', $key)->set('blueprint', true)->pad_blueprint($rs);
                 $form->add($blueprint);
                 continue;
             } elseif ($rs instanceof ORM) {
                 $subform = $rs->get_form($field_name);
                 $form->add($subform);
                 continue;
             }
         }
         if ($this->_field_exists($field_name) !== TRUE) {
             // Custom method looks like _formo_$field_name()
             $method = '_formo_' . $field_name;
             if (!method_exists($this, $method)) {
                 // Throw an exception if a field is requested but there's no method defining its options array
                 throw new Kohana_Exception('Formo custom field method, :method, does not exist.', [':method' => __CLASS__ . '::' . $method . '()']);
             }
             $options = $this->{$method}();
         } else {
             // Create the field definition array
             $options = ['alias' => $field_name, 'val' => $this->{$field_name}, 'driver' => 'input'];
             // Do any special processing if the field is a relational field
             $this->_process_belongs_to($field_name, $options);
             $this->_process_has_one($field_name, $options);
             $this->_process_enum($field_name, $options);
             $this->_process_set($field_name, $options);
         }
         // Add the field to the form
         $form->add($options);
     }
     if ($form->config('model_base_rules') === TRUE) {
         // If form is set up to include basic MySQL mimicking validation rules
         // then figure them out
         $rules = $this->_get_base_rules();
     }
     // Add Model defined rules to base rules
     $rules = isset($rules) ? Arr::merge($rules, $this->rules()) : $this->rules();
     if ($filters = $this->filters()) {
         foreach ($filters as $alias => $_filters) {
             // Add filters as well
             $form->merge($alias, ['filters' => $_filters]);
         }
     }
     // Add the rules to their respective fields
     $form->add_rules_fields($rules);
     $this->formo($form);
     // Load defaults
     $form->ftype();
     return $form;
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:91,代码来源:ORM.php

示例4: create_sub

 /**
  * Create a subform from fields already in the Container object
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver
  * @param mixed array $fields
  * @param mixed $order. (default: NULL)
  * @return object
  */
 public function create_sub($alias, $driver, array $fields, $order = NULL)
 {
     // Create the empty subform object
     $subform = Formo::form($alias, $driver);
     foreach ($fields as $key => $field) {
         if (is_string($key) and !ctype_digit($key)) {
             // Pull fields "as" a new alias
             $new_alias = $field;
             $field = $key;
         }
         // Find each field
         $_field = $this->find($field);
         if (!$_field) {
             // Throw an exception if the field doesn't exist
             throw new Kohana_Exception("Formo_Container: Field {$field} is not in form");
         }
         if (!empty($new_alias)) {
             // Set the new alias
             $_field->alias($new_alias);
         }
         // Remember the field's original parent
         $last_parent = $_field->parent();
         // Add the field to the new subform
         $subform->append($_field);
         // Remove the field from its original parent
         $last_parent->remove($_field->alias());
     }
     // If the parent has a model, copy it to the new subform
     $subform->set('model', $this->get('model'));
     $order and $subform->set('order', $order);
     // Append the new subform
     $this->append($subform);
     return $this;
 }
开发者ID:justus,项目名称:kohana-formo,代码行数:44,代码来源:core.php

示例5: copy_blueprint

 /**
  * Create a copy from form or group object
  *
  * @access public
  * @param array $vals (default: array())
  * @return Formo
  */
 public function copy_blueprint($vals = array())
 {
     // The copy is a new formo object with the count of blueprint copies as its alias
     $blueprint_copy = Formo::form(array('alias' => $this->_blueprint_count, 'blueprint_key' => $this->_blueprint_count));
     $attrs = array_combine(static::$_to_array_attrs, static::$_to_array_attrs);
     $attrs['blueprint_template'] = 'blueprint_template';
     unset($attrs['alias']);
     unset($attrs['driver']);
     unset($attrs['fields']);
     $array = $blueprint_copy->to_array($attrs);
     if ($blueprint_template = $this->get('blueprint_template')) {
         // Look for blueprint_template and set it as the template for each blueprint copy
         $array['template'] = $blueprint_template;
     }
     $blueprint_copy->set($array);
     // Keep track how many blueprints copies have been made
     $this->_blueprint_count++;
     if (!empty($vals) and $vals instanceof ORM) {
         // Look for ORM object and cast it as an array
         $vals = $vals->as_array();
     }
     foreach ($this->_fields as $field) {
         if ($this->_blueprint_count > 0 and is_int($field->alias())) {
             // Don't include other blueprint copies in the fields
             continue;
         }
         $attrs = array_combine(static::$_to_array_attrs, static::$_to_array_attrs);
         unset($attrs['fields']);
         $array = $field->to_array($attrs);
         $alias = $field->alias();
         if (isset($vals[$alias])) {
             $array['val'] = $vals[$alias];
         }
         // Add field definition to blueprint
         $blueprint_copy->add($array);
     }
     return $blueprint_copy;
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:45,代码来源:Formo.php


注:本文中的Formo::form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。