Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:56:22+00:00 2026-06-16T19:56:22+00:00

I am using Doctrine 2 in Zend framework. What I want is to update

  • 0

I am using Doctrine 2 in Zend framework.
What I want is to update a user password, without the user being logged in. Is this the right way to do it in entity class?

public function updatePassword($userId, $new_pass, $em){
    $em->getConnection()->getConfiguration()->setSQLLogger( new \Doctrine\DBAL\Logging\EchoSQLLogger()); 
    $qb = $em->createQueryBuilder();
    $q  = $qb->update('\Application\User\Entity\User', 'u')
            ->set('u.password', $qb->expr()->literal($new_pass))
            ->where('u.userId = ?1')
            ->setParameter(1, "$userId")
            ->getQuery();
    $p = $q->execute();
    return $p;     

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:56:23+00:00Added an answer on June 16, 2026 at 7:56 pm

    The entity class should never utilize the entity manager. The entity class is just a data storage.

    User entity class:

    namespace Entity;
    
    class User {
        // ...
    
        public function setPassword($password)
        {
            $this->password = some_hash_algorythm($password);
            return $this;
        }
    
        // ...
    }
    

    Your controller or whereever you want to update a user’s password:

    $repo = $em->getRepository('Entity\User');
    $user = $repo->find($userId);
    $user->setPassword($newPassword);
    $em->persist($user);
    $em->flush();
    

    This divides the data storage from actual persistence layer.

    If you do not like to have the code in place and want to have it in a central place look in doctrine’s documentation for custom repository classes (they are aware of the entity manager and there for “table-actions”)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using ZF2 with doctrine i am getting this error. The target-entity Entity\User
Using doctrine 2.1 (and zend framework 1.11, not that it matters for this matter),
I'm using Zend Framework and doctrine 1.2.x Is there a way to define index-table
I am using Zend Framework 2 and I have created a User Entity. Now
I've been working with Zend Framework (using Doctrine as the ORM) for quite a
When creating an association using Doctrine 2 and the Zend Framework, if the associated
I have a Zend Framework project using version 1.10.8 with Doctrine 1.2.4.I use Zend_Auth
I'm currently developing a Zend Framework project, using Doctrine as ORM. I ran into
I'm using Doctrine with Zend Framework. For my model, I'm using a base class,
I'm using Zend Framework with Doctrine. I'm creating an object, editing, then saving it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.