public static function addError($messageOrException = 'UNKNOWN', $key = null)
    {
        $formId = Actions::DEFAULT_ERRORS_ID;
        $actionQueryString = Request::getInputValue("do", false, true);
        
        if (!empty($actionQueryString)) {
            $actionQuery = self::parseActionQueryString($actionQueryString);
            $formId = $actionQuery->formId ?? $formId;
        }
        
        if (!array_key_exists($formId, self::$formErrorCache)) {
            self::$formErrorCache[$formId] = array();
        }
        
        if (is_string($messageOrException)) {
            $message = $messageOrException;
            
            $messageOrException = new \stdClass();
            $messageOrException->message = $message;
        }
        else if($messageOrException instanceof \Exception) {
            $readableMessageOrException = new \stdClass();
            
            // include default \Exception fields
            $readableMessageOrException->code = $messageOrException->getCode();
            $readableMessageOrException->message = $messageOrException->getMessage();
            $readableMessageOrException->trace = $messageOrException->getTrace();
            $readableMessageOrException->traceAsString = $messageOrException->getTraceAsString();
            $readableMessageOrException->file = $messageOrException->getFile();
            $readableMessageOrException->line = $messageOrException->getLine();
              
            // include any other accessible fields
            foreach ($messageOrException as $field => $value) {
                $readableMessageOrException->$field = $value;
            }
            
            $messageOrException = $readableMessageOrException;
        }
        
        if ($key !== null) {
            self::$formErrorCache[$formId][$key] = $messageOrException;
        }
        else {
            self::$formErrorCache[$formId][] = $messageOrException;
        }
        
        Cache::getInstance(FlashCache::CACHE_INSTANCE_NAME)->cache($formId, json_encode(self::$formErrorCache[$formId]));
    }
public static function addError($messageOrException = 'UNKNOWN', $key = null)
    {
        $formId = Actions::DEFAULT_ERRORS_ID;
        $actionQueryString = Request::getInputValue("do", false, true);
        
        if (!empty($actionQueryString)) {
            $actionQuery = self::parseActionQueryString($actionQueryString);
            $formId = $actionQuery->formId ?? $formId;
        }
        
        if (!array_key_exists($formId, self::$formErrorCache)) {
            self::$formErrorCache[$formId] = array();
        }
        
        if (is_string($messageOrException)) {
            $message = $messageOrException;
            
            $messageOrException = new \stdClass();
            $messageOrException->message = $message;
        }
        else if($messageOrException instanceof \Exception) {
            $readableMessageOrException = new \stdClass();
            
            // include default \Exception fields
            $readableMessageOrException->code = $messageOrException->getCode();
            $readableMessageOrException->message = $messageOrException->getMessage();
            $readableMessageOrException->trace = $messageOrException->getTrace();
            $readableMessageOrException->traceAsString = $messageOrException->getTraceAsString();
            $readableMessageOrException->file = $messageOrException->getFile();
            $readableMessageOrException->line = $messageOrException->getLine();
              
            // include any other accessible fields
            foreach ($messageOrException as $field => $value) {
                $readableMessageOrException->$field = $value;
            }
            
            $messageOrException = $readableMessageOrException;
        }
        
        if ($key !== null) {
            self::$formErrorCache[$formId][$key] = $messageOrException;
        }
        else {
            self::$formErrorCache[$formId][] = $messageOrException;
        }
        
        Cache::getInstance(FlashCache::CACHE_INSTANCE_NAME)->cache($formId, json_encode(self::$formErrorCache[$formId]));
    }
public static function addError ( $ messageOrException = 'UNKNOWN' , $ key = null ) { $ formId = Actions :: DEFAULT_ERRORS_ID ; $ actionQueryString = Request :: getInputValue ( "do" , false , true ) ; if ( ! empty ( $ actionQueryString ) ) { $ actionQuery = self :: parseActionQueryString ( $ actionQueryString ) ; $ formId = $ actionQuery -> formId ?? $ formId ; } if ( ! array_key_exists ( $ formId , self :: $ formErrorCache ) ) { self :: $ formErrorCache [ $ formId ] = array ( ) ; } if ( is_string ( $ messageOrException ) ) { $ message = $ messageOrException ; $ messageOrException = new \ stdClass ( ) ; $ messageOrException -> message = $ message ; } else if ( $ messageOrException instanceof \ Exception ) { $ readableMessageOrException = new \ stdClass ( ) ; // include default \Exception fields $ readableMessageOrException -> code = $ messageOrException -> getCode ( ) ; $ readableMessageOrException -> message = $ messageOrException -> getMessage ( ) ; $ readableMessageOrException -> trace = $ messageOrException -> getTrace ( ) ; $ readableMessageOrException -> traceAsString = $ messageOrException -> getTraceAsString ( ) ; $ readableMessageOrException -> file = $ messageOrException -> getFile ( ) ; $ readableMessageOrException -> line = $ messageOrException -> getLine ( ) ; // include any other accessible fields foreach ( $ messageOrException as $ field => $ value ) { $ readableMessageOrException -> $ field = $ value ; } $ messageOrException = $ readableMessageOrException ; } if ( $ key !== null ) { self :: $ formErrorCache [ $ formId ] [ $ key ] = $ messageOrException ; } else { self :: $ formErrorCache [ $ formId ] [ ] = $ messageOrException ; } Cache :: getInstance ( FlashCache :: CACHE_INSTANCE_NAME ) -> cache ( $ formId , json_encode ( self :: $ formErrorCache [ $ formId ] ) ) ; }
Add error to the reponse which will be retrievable once after doing a redirect.
Retrievable in templates via the `errors` variable inside a form-tag or _.errors when the action was called from another scope.

@param mixed $messageOrException
The error string, array or object to add.

@param string $key
Optional key for the error.
This allows retrieval of the error directly with the key instead of having to iterate the `errors` variable.
Add error to the reponse which will be retrievable once after doing a redirect . Retrievable in templates via the errors variable inside a form - tag or _ . errors when the action was called from another scope .