本文整理汇总了PHP中Nette\Forms\Form::lookup方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::lookup方法的具体用法?PHP Form::lookup怎么用?PHP Form::lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Form
的用法示例。
在下文中一共展示了Form::lookup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render the templates.
* @param Form $form
* @param string $mode
* @param array $args
*/
public function render(Form $form, $mode = NULL, $args = NULL)
{
if ($this->template === NULL) {
if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
/** @var \Nette\Application\UI\Presenter $presenter */
$this->template = clone $presenter->getTemplate();
} else {
$this->template = new FileTemplate();
$this->template->registerFilter(new \Nette\Latte\Engine());
}
}
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
//$formEl->addClass('form-horizontal');
}
} elseif ($mode === 'begin') {
foreach ($this->form->getControls() as $control) {
/** @var \Nette\Forms\Controls\BaseControl $control */
$control->setOption('rendered', FALSE);
}
}
$this->template->setFile(__DIR__ . '/@form.latte');
$this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
if ($mode === NULL) {
if ($args) {
$this->form->getElementPrototype()->addAttributes($args);
}
$this->template->render();
} elseif ($mode === 'begin') {
FormMacros::renderFormBegin($this->form, (array) $args);
} elseif ($mode === 'end') {
FormMacros::renderFormEnd($this->form);
} else {
$attrs = array('input' => array(), 'label' => array());
foreach ((array) $args as $key => $val) {
if (stripos($key, 'input-') === 0) {
$attrs['input'][substr($key, 6)] = $val;
} elseif (stripos($key, 'label-') === 0) {
$attrs['label'][substr($key, 6)] = $val;
}
}
$this->template->setFile(__DIR__ . '/@parts.latte');
$this->template->mode = $mode;
$this->template->attrs = (array) $attrs;
$this->template->render();
}
}
示例2: render
/**
* Render the templates
*
* @param \Nette\Forms\Form $form
* @param string $mode
* @param array $args
* @return void
*/
public function render(Nette\Forms\Form $form, $mode = NULL, $args = NULL)
{
if ($this->template === NULL) {
if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
/** @var \Nette\Application\UI\Presenter $presenter */
$this->template = clone $presenter->getTemplate();
} else {
$this->template = new Nette\Bridges\ApplicationLatte\Template(new Nette\Latte\Engine());
}
}
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
$this->horizontalMode = $this->mode === self::MODE_HORIZONTAL;
if ($this->mode !== self::MODE_NO_CLASS) {
$formEl->addClass($this->mode);
}
}
} elseif ($mode === 'begin') {
foreach ($this->form->getControls() as $control) {
/** @var \Nette\Forms\Controls\BaseControl $control */
$control->setOption('rendered', FALSE);
}
}
$this->template->setFile(__DIR__ . '/@form.latte');
$this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
if ($this->horizontalMode) {
$this->template->labelCols = $this->labelColumns;
$this->template->inputCols = $this->inputColumns;
$this->template->labelClass = $this->columnClassPrefix . $this->labelColumns;
$this->template->inputClass = $this->columnClassPrefix . $this->inputColumns;
$this->template->skipClass = $this->columnClassPrefix . 'offset-' . $this->labelColumns;
}
if ($mode === NULL) {
if ($args) {
$this->form->getElementPrototype()->addAttributes($args);
}
$this->template->render();
} elseif ($mode === 'begin') {
FormMacros::renderFormBegin($this->form, (array) $args);
} elseif ($mode === 'end') {
FormMacros::renderFormEnd($this->form);
} else {
$attrs = array('input' => array(), 'label' => array(), 'pair' => array(), 'pair-class' => '');
foreach ((array) $args as $key => $val) {
if (stripos($key, 'input-') === 0) {
$attrs['input'][substr($key, 6)] = $val;
} elseif (stripos($key, 'label-') === 0) {
$attrs['label'][substr($key, 6)] = $val;
} elseif ($key === 'class') {
$attrs['pair-class'] = $val;
} else {
$attrs['pair'][$key] = $val;
}
}
if ($this->horizontalMode) {
if (isset($attrs['label']['class'])) {
$attrs['label']['class'] .= ' ' . $this->columnClassPrefix . $this->labelColumns;
} else {
$attrs['label']['class'] = $this->columnClassPrefix . $this->labelColumns;
}
}
$this->template->setFile(__DIR__ . '/@parts.latte');
$this->template->mode = $mode;
$this->template->attrs = (array) $attrs;
$this->template->render();
}
}
示例3: render
public function render(Nette\Forms\Form $form)
{
$presenter = $form->lookup(Nette\Application\UI\Presenter::class, FALSE);
if ($presenter instanceof Ytnuk\Application\Presenter) {
$templating = $presenter->createComponent('templating');
$templating->setParent($this);
if (!iterator_to_array($file = $templating['view'])) {
return NULL;
}
$template = $presenter->getTemplateFactory()->createTemplate($form->lookup(Nette\Application\UI\Control::class, FALSE));
if (!$template instanceof Nette\Bridges\ApplicationLatte\Template) {
return NULL;
}
$template->setFile($file);
$template->setParameters(['form' => $form, '_form' => $this]);
return (string) $template;
}
return NULL;
}