3
votes

I have a problem with deleting user with $UserManager->deleteUser($user). I'm getting an error: Error: Class AppBundle\Controller\UsermanagerController contains 35 abstract methods and must therefore be declared abstract or implement the remaining methods.

My Controller:

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\UserManager;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class UsermanagerController extends Controller implements UserInterface
{
public function deleteAction($user){
$UserManager = $this->container->get('fos_user.user_manager');
if ($user ==  null) {
        throw new NotFoundHttpException('User not found for user ' . $user);
    }
$UserManager->deleteUser($user);
return $this->redirect($this->generateUrl('admin_index'));

}

My Entity:

namespace AppBundle/Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Doctrine\UserManager as BaseCustomer;
use FOS\UserBundle\Model\UserInterface;

/**
*@ORM|Entitiy
*
*/
class UserManager extends BaseCustomer implements UserInterface
{

}

My config.yml: orm:

resolve_target_entities:
    FOS\UserBundle\Model\UserInterface: AppBundle\Entity\UserManager

And Routing.yml:

fos_deleteuser_group:
    path: /app/usermanager/delete/{user}
    defaults: { _controller: AppBundle:Usermanager:delete }

I tried to use FOS/UserBundle/doctrine/UserManager, no luck.

Thanks for your help in advance.

1

1 Answers

2
votes

To summarize:

Your first error was that implements UserInterface in the controller. you've removed it.

Then you have another problem inside of your controller because you pass a string to the UserManager::deleteUser method which expects some UserInterface

I will provide some code for you, which should fix that.

<?php
/**
 * @param $username string
 * @return Response
 */
public function deleteAction($username) {
  $userManager = $this->get('fos_user.user_manager');
  /* @var $userManager UserManager */

  $user = $userManager->findUserByUsername($username);
  if(\is_null($user)) {
    // user not found, generate $notFoundResponse
    return $notFoundResponse;
  }

  \assert(!\is_null($user));
  $userManager->deleteUser($user);

  // okay, generate $okayResponse
  return $okayResponse;
}