Exemplo n.º 1
0
Arquivo: Form.php Projeto: hjr3/titon
 /**
  * Open a form by outputting the form open tag.
  *
  * @access public
  * @param string $model
  * @param array $attributes
  * @return string
  */
 public function open($model, array $attributes = array())
 {
     if (!empty($model) && is_string($model)) {
         $model = Inflector::modelize($model);
         $this->_model = $model;
     }
     // Form type
     if (isset($attributes['type'])) {
         if ($attributes['type'] == 'file') {
             $attributes['enctype'] = 'multipart/form-data';
         }
         unset($attributes['type']);
     }
     // Fieldset legend
     $legend = null;
     if (isset($attributes['legend'])) {
         $legend = $attributes['legend'];
         unset($attributes['legend']);
     }
     // Attributes
     $attributes = array_merge(array('method' => 'post', 'action' => '', 'id' => $this->_model . 'Form'), $attributes);
     if (!empty($attributes['action'])) {
         $attributes['action'] = Router::construct(Router::detect($attributes['action']));
     }
     $output = $this->tag('form_open', $this->attributes($attributes));
     // If legend, add fieldset
     if (isset($legend)) {
         $attributes['legend'] = $legend;
         $output .= $this->tag('fieldset_open');
         $output .= $this->tag('legend', $legend);
     }
     // Save its state
     $this->_forms[$this->_model] = $attributes;
     return $output;
 }