dragon5006 2015-03-16 19:31
浏览 25
已采纳

FOSuserBundle中的DeleteUser方法symfony 2用户界面错误

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条回答 默认 最新

  • dqd78456 2015-03-16 20:46
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输