dragon5006 2015-03-16 11: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 12: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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部