當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Form::setTranslator方法代碼示例

本文整理匯總了PHP中Nette\Forms\Form::setTranslator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::setTranslator方法的具體用法?PHP Form::setTranslator怎麽用?PHP Form::setTranslator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\Forms\Form的用法示例。


在下文中一共展示了Form::setTranslator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: translate

    private $table;
    function __construct(array $table)
    {
        $this->table = $table;
    }
    /**
     * Translates the given string.
     */
    public function translate($message, $count = NULL)
    {
        return isset($this->table[$message]) ? $this->table[$message] : $message;
    }
}
$form = new Form();
$translator = new MyTranslator(parse_ini_file(__DIR__ . '/localization.ini'));
$form->setTranslator($translator);
$form->addGroup('Personal data');
$form->addText('name', 'Your name:')->setRequired('Enter your name');
$form->addText('age', 'Your age:')->setRequired('Enter your age')->addRule($form::INTEGER, 'Age must be numeric value')->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
$countries = ['World' => ['bu' => 'Buranda', 'qu' => 'Qumran', 'st' => 'Saint Georges Island'], '?' => 'other'];
$form->addSelect('country', 'Country:', $countries)->setPrompt('Select your country');
$form->addSubmit('submit', 'Send');
if ($form->isSuccess()) {
    echo '<h2>Form was submitted and successfully validated</h2>';
    Dumper::dump($form->getValues());
    exit;
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
<title>Nette Forms localization example</title>
開發者ID:jjanekk,項目名稱:forms,代碼行數:31,代碼來源:localization.php


注:本文中的Nette\Forms\Form::setTranslator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。