Get forgot password link in magento2
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am trying to get forgot password link in my controller with below code
class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Its not working. Please anyone suggest on this.
magento2 controllers customer-account
add a comment |Â
up vote
1
down vote
favorite
I am trying to get forgot password link in my controller with below code
class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Its not working. Please anyone suggest on this.
magento2 controllers customer-account
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to get forgot password link in my controller with below code
class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Its not working. Please anyone suggest on this.
magento2 controllers customer-account
I am trying to get forgot password link in my controller with below code
class CreatePost extends MagentoFrameworkAppActionAction
{
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_customerForgotUrl->getForgotPasswordUrl();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Its not working. Please anyone suggest on this.
magento2 controllers customer-account
edited Aug 14 at 10:08
asked Aug 14 at 6:44
jafar pinjar
357110
357110
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23
add a comment |Â
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Try this:
class CreatePost extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in__construct
because__construct
method already inMagentoFrameworkAppActionAction
.
â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
 |Â
show 3 more comments
up vote
1
down vote
EDIT - Based on your code
class CreatePost extends MagentoFrameworkAppActionAction
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Try this:
class CreatePost extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in__construct
because__construct
method already inMagentoFrameworkAppActionAction
.
â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
 |Â
show 3 more comments
up vote
1
down vote
accepted
Try this:
class CreatePost extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in__construct
because__construct
method already inMagentoFrameworkAppActionAction
.
â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
 |Â
show 3 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Try this:
class CreatePost extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);
Try this:
class CreatePost extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context
)
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
$url = $this->_url->getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->messageManager->addErrorMessage($message);
edited Aug 14 at 8:13
answered Aug 14 at 6:52
kunj
2,3672420
2,3672420
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in__construct
because__construct
method already inMagentoFrameworkAppActionAction
.
â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
 |Â
show 3 more comments
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in__construct
because__construct
method already inMagentoFrameworkAppActionAction
.
â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
Anything i need to construct to use _url? Directly can i use above code?
â jafar pinjar
Aug 14 at 6:56
No, in the controller it does not need to add anything in
__construct
because __construct
method already in MagentoFrameworkAppActionAction
.â kunj
Aug 14 at 6:58
No, in the controller it does not need to add anything in
__construct
because __construct
method already in MagentoFrameworkAppActionAction
.â kunj
Aug 14 at 6:58
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
I used your code , its not working
â jafar pinjar
Aug 14 at 7:02
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
@jafar, May I have your controller code?
â kunj
Aug 14 at 7:03
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
Updated my code, please take a look.
â jafar pinjar
Aug 14 at 7:07
 |Â
show 3 more comments
up vote
1
down vote
EDIT - Based on your code
class CreatePost extends MagentoFrameworkAppActionAction
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
add a comment |Â
up vote
1
down vote
EDIT - Based on your code
class CreatePost extends MagentoFrameworkAppActionAction
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
add a comment |Â
up vote
1
down vote
up vote
1
down vote
EDIT - Based on your code
class CreatePost extends MagentoFrameworkAppActionAction
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
EDIT - Based on your code
class CreatePost extends MagentoFrameworkAppActionAction
protected $_messageManager;
protected $customerForgotUrl;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoCustomerModelUrl $customerForgotUrl
)
$this->_messageManager = $messageManager;
$this->_customerForgotUrl = $customerForgotUrl;
parent::__construct($context);
public function execute()
try
$user->save();
catch (MagentoFrameworkExceptionAlreadyExistsException $e)
echo $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
echo $url2 = $this->_url->getUrl('customer/account/forgotpassword');
die();
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_messageManager()->addError($message);
edited Aug 14 at 8:00
answered Aug 14 at 6:56
LAW
623416
623416
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
add a comment |Â
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
Tried this also, Its not working
â jafar pinjar
Aug 14 at 7:09
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I used this code getting error like this, PHP Fatal error: Uncaught Error: Call to undefined method at line $url1 = $this->_customerForgotUrl->getForgotPasswordUrl();
â jafar pinjar
Aug 14 at 7:51
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
I believe that will not be needed for you. The link will work using $url2. That I wrote just for you to check. You can comment that out.
â LAW
Aug 14 at 7:53
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
so injecting _customerForgotUrl is not required?
â jafar pinjar
Aug 14 at 7:58
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
Yes should not be needed, I have updated my answer, the issue with your code was with execute function
â LAW
Aug 14 at 8:00
add a comment |Â
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f238276%2fget-forgot-password-link-in-magento2%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Seems to me like you are not using execute method. Can you check the updated answer. I have added die.
â LAW
Aug 14 at 7:23