1

I'm trying to save the display name of a user account using ZfcUser as a base to create my own API, but unfortunately I couldn't. This is my code:

$service = $this->getUserService();
$form = $this->getPostData();
$post = array(
        "email" => $form->{'email'},
        "password" => $form->{'password'},
        "passwordVerify" => $form->{'password'},
        "display_name" => $form->{'name'},
        "submit" => ""
        );

$service->register($post);
return new JsonModel($this->postToArray($form));
  • Do you have option "enable_display_name" set on true? Default value is false and in that case is display name skipped from validation, hydration and so on in UserService. – lku Jun 09 '14 at 16:23
  • Yeah, I actually try to set this line: $service->getOptions()->setEnableDisplayName(true); before $service->register($post), but it didn't work... It isn't saving the display_name in the DB. Thanks anyway – Javier De La Hoz Jun 09 '14 at 16:46
  • Even if I print the $user array I get this: object(ZfcUserDoctrineMongoODM\Document\User)#295 (6) { ["id":protected]=> string(24) "5395e69e1c785a3e721446ab" ["username":protected]=> NULL ["email":protected]=> string(22) "javierdlahoz@gmail.com" ["displayName":protected]=> string(12) "javierdlahoz" ["password":protected]=> string(60) "$2y$14$Qbs5Lp/E7KKfAlfMoliyQuORofEMtIXSr0Wa8XHALHJi.i68le5Oq" ["state":protected]=> NULL } But display_name is null on the user document – Javier De La Hoz Jun 09 '14 at 16:54
  • Well, it may not be enough (set it via setter somewhere) for example, register form could be already cached in user service with removed field for display_name. Try to set it in configuration file. – lku Jun 09 '14 at 17:17
  • I'm gonna try, but actually, if I set this line $service->getOptions()->setEnableUsername(true); I can add username field to the user document, so it should work in the same way for display_name – Javier De La Hoz Jun 09 '14 at 18:10
  • Now I noticed difference between display_name in your code and displayName in data (camelCase vs underscore_case). What is in your XML mapping? – lku Jun 09 '14 at 18:25
  • 1
    I solved this little problem extending the User Entity and using annotations instead of XML, so thanks for your replies – Javier De La Hoz Jun 10 '14 at 13:55

0 Answers0