Вызов функции-члена на нуль

Я создаю сервис для добавления formType, затем сохраняю объект и в контроллере я вызываю данные, но у меня есть ошибка, показанная на изображении ниже:

в контроллере я расширяю класс abstractController содержимого getHandler и у меня есть представление newskill.html.twig

введите описание изображения здесь

Код SkillController.php:

<?php

namespace AppBundle\Controller\Condidate;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Skill;
use AppBundle\Controller\AbstractController;
use AppBundle\Form\SkillType;

/**
*Class SkillController.
*/
class SkillController extends AbstractController
{

/**
*function handler.
*/
protected function getHandler(){
//var_dump('test');
}

/**
*function addSkill
* @param Request $request
* @return \Symfony\Component\Form\Form The form
*/
public function addSkillAction(Request $request) {
$skill = $this->getHandler()->post();

if ($skill instanceof \AppBundle\Entity\Skill) {
return $this->redirectToRoute('ajouter_info');

}

return $this->render('skills/newskill.html.twig', array(
'form' => $form->createView(),));

}}

Код SkillHandler.php:

<?php

namespace AppBundle\Handler;

use AppBundle\Handler\HandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Skill;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\formFactory;

/**
* SkillHandler.
*/
class SkillHandler implements HandlerInterface {

/**
*
* @var EntityManager
*/
protected $em;

/**
*
* @var formFactory
*/
private $formFactory;/**
*function construct.
*/
public function __construct(EntityManager $entityManager, formFactory $formFactory)
{
$this->em = $entityManager;
$this->formFactory = $formFactory;
}

/**
*function post
*/
public function post(array $parameters, array $options = []) {
$form = $this->formFactory->create(\AppBundle\Form\SkillType::class, $object, $options);
$form->submit($parameters);
if ($form->isValid()) {
$skill = $form->getData();
$this->persistAndFlush($skill);
return $skill;
}

return $form->getData();
}

/**
*function persisteAndFlush
*/

protected function persistAndFlush($object) {
$this->em->persist($object);
$this->em->flush();
}/**
*function get
*/
public function get($id){
throw new \DomainException('Method SkillHandler::get not implemented');

}

/**
*function all
*/
public function all($limit = 10, $offset = 0){
throw new \DomainException('Method SkillHandler::all not implemented');
}/**
*function put
*/
public function put($resource, array $parameters, array $options){
throw new \DomainException('Method SkillHandler::put not implemented');
}

/**
*function patch
*/
public function patch($resource, array $parameters, array $options){
throw new \DomainException('Method SkillHandler::patch not implemented');
}

/**
*function delete
*/
public function delete($resource){
throw new \DomainException('Method SkillHandler::delete not implemented');
}
}

код services.yml:

skill_add:
class: AppBundle\Handler\SkillHandler
arguments:
- "@doctrine.orm.entity_manager"- "@form.factory"public: true

Любая помощь будет оценена.

1

Решение

Попробуйте это, во-первых, вы должны взять свой обработчик в метод getHandler () на вашем контроллере.

protected function getHandler(){
return $this->get('skill_add');
}
0

Другие решения

Ваш $this->getHandler() Retruns null,

Решение может быть проверка, если $this->getHandler() не возвращается null На первом месте.

if (!$this->getHandler()) {
throw new \Exception(sprintf('Handler cannot be null')
} else {
$skill = $this->getHandler()->post();
}
3

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector