Ejemplo n.º 1
0
 /**
  * Returns the submitted or default value of this variable.
  * If an action is attached to this variable, the value will get passed to
  * the action object.
  *
  * @param Variables $vars  The {@link Variables} instance of the submitted
  *                         form.
  * @param integer $index   If the variable is an array variable, this
  *                         specifies the array element to return.
  *
  * @return mixed  The variable or element value.
  */
 function getValue($vars, $index = null)
 {
     if ($this->_arrayVal) {
         $name = str_replace('[]', '', $this->varName);
     } else {
         $name = $this->varName;
     }
     $value = $vars->getExists($name, $wasset);
     if (!$wasset) {
         $value = $this->getDefault();
     }
     if ($this->_arrayVal && !is_null($index)) {
         if (!$wasset && !is_array($value)) {
             $return = $value;
         } else {
             $return = isset($value[$index]) ? $value[$index] : null;
         }
     } else {
         $return = $value;
     }
     if ($this->hasAction()) {
         $this->_action->setValues($vars, $return, $this->_arrayVal);
     }
     return $return;
 }