本文整理汇总了PHP中Zend_Form::getTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::getTranslator方法的具体用法?PHP Zend_Form::getTranslator怎么用?PHP Zend_Form::getTranslator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form
的用法示例。
在下文中一共展示了Zend_Form::getTranslator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _recursivelyPrepareForm
protected function _recursivelyPrepareForm(Zend_Form $form)
{
$belongsTo = $form instanceof Zend_Form ? $form->getElementsBelongTo() : null;
$elementContent = '';
$separator = $this->getSeparator();
$translator = $form->getTranslator();
$view = $form->getView();
foreach ($form as $item) {
$item->setView($view)->setTranslator($translator);
if ($item instanceof Zend_Form_Element) {
$item->setBelongsTo($belongsTo);
} elseif (!empty($belongsTo) && $item instanceof Zend_Form) {
if ($item->isArray()) {
$name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
$item->setElementsBelongTo($name, true);
} else {
$item->setElementsBelongTo($belongsTo, true);
}
$this->_recursivelyPrepareForm($item);
} elseif (!empty($belongsTo) && $item instanceof Zend_Form_DisplayGroup) {
foreach ($item as $element) {
$element->setBelongsTo($belongsTo);
}
}
}
}
示例2: testTranslatorFromRegistryUsedWhenNoneRegistered
public function testTranslatorFromRegistryUsedWhenNoneRegistered()
{
$this->assertNull($this->form->getTranslator());
$translator = new Zend_Translate('array', array());
Zend_Registry::set('Zend_Translate', $translator);
$received = Zend_Form::getDefaultTranslator();
$this->assertSame($translator->getAdapter(), $received);
$received = $this->form->getTranslator();
$this->assertSame($translator->getAdapter(), $received);
$form = new Zend_Form();
$received = $form->getTranslator();
$this->assertSame($translator->getAdapter(), $received);
}
示例3: addElementProjectStatus
/**
* Adds an element Status of Project as a Combobox.<br/>
* Defaults:<br/>
* name = status<br/>
* required = true<br/>
* label = Status<br/>
* dimension = 6<br/>
* modelfield = status<br/>
* class = selectpicker<br/>
* first-options= must be and array of array('value1', 'label'). Default is an empty array<br/>
* sample of first-options: array(array('value'=>null, 'label'=>'Choose an option'))
*
* @param Zend_Form $form The Zend_Form object where the element will be added
* @param array $options The options to pass in the element
* @return Zend_Form_Element Zend Form element just created
*/
public function addElementProjectStatus($form, $options = array())
{
$elementName = isset($options['name']) ? $options['name'] : 'status';
$modelField = isset($options['modelfield']) ? $options['modelfield'] : 'status';
$form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'Status', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 6, 'required' => isset($options['required']) ? $options['required'] : true, 'value' => $this->_model ? $this->_model->{$modelField} : '', 'class' => isset($options['class']) ? $options['class'] : 'selectpicker'));
$el = $form->getElement($elementName);
if (isset($options['first-options'])) {
foreach ($options['first-options'] as $op) {
$el->addMultiOption($op['value'], $op['label']);
}
}
$el->addMultiOption(Project_Model_Project::PROJECT_STATUS_DRAFT_ID, Project_Model_Project::PROJECT_STATUS_DRAFT_LABEL);
$el->addMultiOption(Project_Model_Project::PROJECT_STATUS_ACTIVE_ID, Project_Model_Project::PROJECT_STATUS_ACTIVE_LABEL);
$el->addMultiOption(Project_Model_Project::PROJECT_STATUS_FINISHED_ID, Project_Model_Project::PROJECT_STATUS_FINISHED_LABEL);
$el->addMultiOption(Project_Model_Project::PROJECT_STATUS_CLOSED_ID, Project_Model_Project::PROJECT_STATUS_CLOSED_LABEL);
$el->addMultiOption(Project_Model_Project::PROJECT_STATUS_PAUSED_ID, Project_Model_Project::PROJECT_STATUS_PAUSED_LABEL);
$optionClasses[] = '" data-content="<span class=\'label\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_DRAFT_LABEL) . '</span>';
$optionClasses[] = '" data-content="<span class=\'label label-success\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_ACTIVE_LABEL) . '</span>';
$optionClasses[] = '" data-content="<span class=\'label label-info\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_FINISHED_LABEL) . '</span>';
$optionClasses[] = '" data-content="<span class=\'label label-inverse\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_CLOSED_LABEL) . '</span>';
$optionClasses[] = '" data-content="<span class=\'label label-warning\'>' . $form->getTranslator()->_(Project_Model_Project::PROJECT_STATUS_PAUSED_LABEL) . '</span>';
$el->setAttrib('optionClasses', $optionClasses);
if ($this->_model && $this->_model->{$modelField}) {
$el->setValue($this->_model->{$modelField});
} else {
$el->setValue(null);
}
return $el;
}
示例4: testCanDisableTranslation
public function testCanDisableTranslation()
{
$this->testCanSetDefaultGlobalTranslator();
$this->form->setDisableTranslator(true);
$this->assertNull($this->form->getTranslator());
}
示例5: initTranslation
protected function initTranslation(\Zend_Form $form, $id, $locale = null)
{
if ($locale === null) {
$locale = \Zend_Locale::findLocale();
}
$trans = $this->translateForm($id, $locale);
if ($locale != null && $locale != "") {
if (null === $form->getTranslator()) {
$form->setTranslator($trans);
} else {
$form->getTranslator()->addTranslation($trans);
}
}
}