Frontend\Core\Language\Language::getError PHP Метод

getError() публичный статический Метод

Get an error from the language-file
public static getError ( string $key, boolean $fallback = true ) : string
$key string The key to get.
$fallback boolean Should we provide a fallback in English?
Результат string
    public static function getError($key, $fallback = true)
    {
        // redefine
        $key = \SpoonFilter::toCamelCase((string) $key);
        // if the error exists return it,
        if (isset(self::$err[$key])) {
            return self::$err[$key];
        }
        // If we should fallback and the fallback label exists, return it
        if (isset(self::$fallbackErr[$key]) && $fallback === true && Model::getContainer()->getParameter('kernel.debug') === false) {
            return self::$fallbackErr[$key];
        }
        // otherwise return the key in label-format
        return '{$err' . $key . '}';
    }

Usage Example

Пример #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     $txtEmail->addError(FL::getError('EmailIsUnknown'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // generate forgot password key
             $key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString());
             // insert forgot password key
             FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key);
             // reset url
             $mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $key;
             $mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name');
             $mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name');
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_forgot_password', array('id' => $profileId));
             // send email
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = Message::newInstance(FL::getMessage('ForgotPasswordSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Profiles/Layout/Templates/Mails/ForgotPassword.html.twig', $mailValues, true);
             $this->get('mailer')->send($message);
             // redirect
             $this->redirect(SITE_URL . $this->URL->getQueryString() . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }
All Usage Examples Of Frontend\Core\Language\Language::getError