在Nette表单中添加自定义控件需要以下步骤:
use Nette\Forms\Controls\TextBase;
class MyCustomControl extends TextBase
{
public function __construct($label = null, $maxLength = null)
{
parent::__construct($label, $maxLength);
$this->setOption('type', 'myCustomControl');
}
public function getControl()
{
$control = parent::getControl();
$control->type = $this->getOption('type');
return $control;
}
}
$form = new Nette\Forms\Form;
$form->addText('name', 'Your name:')
->setRequired();
$form->addControl(new MyCustomControl('My Custom Control:'));
{%block myCustomControl%}
{include parent}
{%/block%}
通过以上步骤,便可以在Nette表单中添加自定义控件。
上一篇:Addingcustomattributes(visibility!)toaWordPressBlog
下一篇:AddingcustomReferencetoAsp.NetprojectandCHTMLpagedoesnotseeit