I want to call method inside class that creates form. But I get this error.
Error: Call to a member function get() on null
This is class that should handle form operations.
class CommentController extends Controller
{
public function replyAction()
{
$comment = new Comments();
$form = $this->createFormBuilder($comment)
->add('name', TextType::class)
->add('text', TextType::class)
->add('reply', SubmitType::class, array(
'label' => 'Reply'))
->getForm();
return $this->$form;
}
}
and this is how i Call the method from another class
$form = (new CommentController())->replyAction();
It works if I place the replyAction
code into class that I am calling it from, but I want to have it inside separate class.