Sunday, 15 April 2012

php - DeleteUser method in FOSuserBundle symfony 2 Userinterface error -


I have a problem deleting user with $ UserManager-> deleteUser ($ user). I am getting an error: Error: Class AppBundle \ Controller \ UsermanagerController has 35 abstract methods and therefore they must apply abstract methods to summarize or declare them.

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 Expands Controller User Interface {Public Function deleteAction ($ user) {$ UserManager = $ this- & gt; Container-> Obtain ('fos_user.user_manager'); If ($ user == faucet) {New Nottold HTTP Exception ('User not found for user'. $ User); } $ UserManager- & gt; Delete user ($ user); $ $ - this- & gt; Redirect ($ this - & amp; generUrl ('admin_index')); }  

My entity:

  Namespace AppBundle / Entity; Use the theory / ORM \ mapping as an ORM; Use FOS \ UserBundle \ Doctrine \ UserManager as BaseCustomer; Use FOS \ UserBundle \ Model \ UserInterface; / ** * @ ORM | Entryy * * / class UserManager BaseCustomer implements UserInterface {}  

My config.yml: orm:

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

and routing. Assam:

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

/ UserBundle / doctrine / UserManager, tried using any luck.

Thanks in advance for your help

In short:

Your first error was that implements the user interface in the admin you have removed it.

Then you have another problem inside your controller because you pass the string to the UserManager :: deleteUser method which is something UserInterface

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

  & lt ;? Php / ** * @ Ultimate $ username string * @ Return Response * / Public Function Deletion Action ($ user name) {$ userManager = $ this- & gt; Obtain ('fos_user.user_manager'); / * @ $$ User Manager User Manager * / $ user = $ userManager- & gt; FindUserByUsername ($ username); If (\ is_null ($ user)) {// user not found, $ notFoundResponse returns $ notFoundResponse; } \ Assert (! \ Is_null ($ user)); $ UserManager- & gt; DeleteUser ($ user); // OK, generate $ OK Response Returns $ OKHrsons; }  

No comments:

Post a Comment