Esempio n. 1
0
File: Form.php Progetto: hjr3/titon
 /**
  * Create a single checkbox element, or multiple checkboxes if an 'options' array is passed.
  *
  * @access public
  * @param string $input
  * @param array $options
  * @param array $attributes
  *      - default: The radio to be selected by default
  *      - label: Enable or disable the label, or supply a new string to be used (single radio)
  * @return string
  */
 public function radio($input, array $options = array(), array $attributes = array())
 {
     $attributes = $this->_prepareInput(array('name' => $input, 'type' => 'radio'), $attributes);
     $selected = null;
     $output = null;
     $label = true;
     // Value
     if (isset($attributes['value'])) {
         $selected = $attributes['value'];
     } else {
         if (isset($attributes['default'])) {
             $selected = $attributes['default'];
         }
     }
     // Show or hide label
     if (isset($attributes['label'])) {
         $label = $attributes['label'];
     } else {
         $label = Inflector::normalize($input);
     }
     // Multiple radios
     foreach ($options as $value => $title) {
         $radio = $attributes;
         $radio['id'] = $radio['id'] . Inflector::camelize($value);
         $radio['value'] = $value;
         if ($selected == $value) {
             $radio['checked'] = 'checked';
         }
         $output .= '<span class="form-radio">';
         $output .= $this->tag('input', $this->attributes($radio, array('label', 'options', 'default')));
         if ($label && !empty($title)) {
             $output .= $this->label($input . '_' . $value, $title);
         }
         $output .= '</span>';
     }
     return $output;
 }
Esempio n. 2
0
 /**
  * Allows you to throw up an error page. The error template is derived from the $action passed.
  *
  * @access public
  * @param string $action
  * @param array $args
  * @return void
  */
 public function error($action, array $args = array())
 {
     if (!isset($args['pageTitle'])) {
         switch ($action) {
             case is_numeric($action):
                 $args['pageTitle'] = $action;
                 if ($title = $this->Response->statusCode($action)) {
                     $args['pageTitle'] .= ' - ' . $title;
                     $this->Response->status($action);
                 }
                 break;
             default:
                 $args['pageTitle'] = Inflector::normalize($action);
                 break;
         }
     }
     // Build arguments
     $args['referrer'] = $this->Request->referrer();
     $args['url'] = 'todo';
     //Router::construct(Router::current());
     $this->View->set($args);
     $this->View->configure(array('error' => true, 'layout' => 'error', 'template' => $action));
     return;
 }