Form Factory – What am I am doing wrong

Notice: This thread is very old.
simonjcarr
Member | 28
+
0
-

I am just getting started with nette. I have installed the nette/sandbox and am trying to use the signUpFormFactory

However the documentation provided (see below) produces errors

protected function createComponentSignInForm()
{
    $form = (new SignInFormFactory)->create();
    $form['login']->caption = 'Continue'; // we can also modify our form

    $form->onSuccess[] = [$this, 'signInFormSubmitted']; // and add event handlers

    return $form;
}
Class 'App\Presenters\SignInFormFactory' not found search►

If I run

protected function createComponentSignInForm()
{
    $form = (new \App\Forms\SignInFormFactory)->create();
    $form['login']->caption = 'Continue'; // we can also modify our form

    $form->onSuccess[] = [$this, 'signInFormSubmitted']; // and add event handlers

    return $form;
}

I get the following error

Argument 1 passed to App\Forms\SignInFormFactory::__construct() must be an instance of App\Forms\FormFactory, none given, called in E:\wamp64\www\ukcommunity\app\presenters\HomepagePresenter.php on line 21 and defined

Is there some clear/concise documentation on how to use the Form Factory that is included with the sandbox?

CZechBoY
Member | 3608
+
0
-

Get factory from dependency injection container.

class HomepagePresenter extends Nette\Application\UI\Presenter
{
	public function __construct(App\Forms\SignInFormFactory $signInFormFactory)
	{
		parent::__construct();

		$this->signInFormFactory = $signInFormFactory;
	}

	protected function createComponentSignInForm()
	{
		$form = $this->signInFormFactory->create();

	    $form['login']->caption = 'Continue'; // we can also modify our form

    	$form->onSuccess[] = [$this, 'signInFormSubmitted']; // and add event handlers

		return $form;
	}
}

And if you dont have yet in your config.neon file, register as service to dependency injection container:

services:
	- App\Forms\SignInFormFactory