How to redirect customer from controller not observer to login page magento 2
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I want to redirect customer to login page in my controller without using observer.
here is my code
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($login_url);
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
but as result i have no redirection response please help me and thanks in advance
magento2 login
add a comment |Â
up vote
2
down vote
favorite
I want to redirect customer to login page in my controller without using observer.
here is my code
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($login_url);
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
but as result i have no redirection response please help me and thanks in advance
magento2 login
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to redirect customer to login page in my controller without using observer.
here is my code
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($login_url);
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
but as result i have no redirection response please help me and thanks in advance
magento2 login
I want to redirect customer to login page in my controller without using observer.
here is my code
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setUrl($login_url);
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
but as result i have no redirection response please help me and thanks in advance
magento2 login
magento2 login
edited 4 hours ago
Amit Beraâ¦
54k1366157
54k1366157
asked 4 hours ago
Developper Magento
977
977
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
Your code should be looking like something below, your controller is missing the execute()
method which is the entry point for the controller action in Magento 2 and return
statement which returns the redirection url. Your code should look like something below:
<?php
namespace YourNameSpace;
class YourClassName
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
public function execute()
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
return $this->resultRedirectFactory->create()->setPath($login_url);
?>
add a comment |Â
up vote
2
down vote
Try something like this
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You need to return the ResultRedirect
object inside your execute()
method
add a comment |Â
up vote
1
down vote
You have to redirection from execute(), in your code . You did not build Action class properly.
And your code it is missing this function.
public function execute()
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
add a comment |Â
up vote
1
down vote
Use below code
<?php
namespace VenorModuleControllerIndex;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use MagentoCustomerModelSession;
use MagentoFrameworkAppResponseHttp;
use MagentoFrameworkUrlInterface;
class Index extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkAppResponseHttp $http
)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
$this->_pageFactory = $pageFactory;
$this->_http = $http;
public function execute()
$login_url = $this->urlInterface->getUrl('customer/account/login');
$this->_http->setRedirect($login_url, 301);
$pageFactory = $this->_pageFactory->create();
return $pageFactory;
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Your code should be looking like something below, your controller is missing the execute()
method which is the entry point for the controller action in Magento 2 and return
statement which returns the redirection url. Your code should look like something below:
<?php
namespace YourNameSpace;
class YourClassName
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
public function execute()
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
return $this->resultRedirectFactory->create()->setPath($login_url);
?>
add a comment |Â
up vote
1
down vote
accepted
Your code should be looking like something below, your controller is missing the execute()
method which is the entry point for the controller action in Magento 2 and return
statement which returns the redirection url. Your code should look like something below:
<?php
namespace YourNameSpace;
class YourClassName
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
public function execute()
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
return $this->resultRedirectFactory->create()->setPath($login_url);
?>
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Your code should be looking like something below, your controller is missing the execute()
method which is the entry point for the controller action in Magento 2 and return
statement which returns the redirection url. Your code should look like something below:
<?php
namespace YourNameSpace;
class YourClassName
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
public function execute()
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
return $this->resultRedirectFactory->create()->setPath($login_url);
?>
Your code should be looking like something below, your controller is missing the execute()
method which is the entry point for the controller action in Magento 2 and return
statement which returns the redirection url. Your code should look like something below:
<?php
namespace YourNameSpace;
class YourClassName
protected $urlInterface;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
public function execute()
// Create login URL
$login_url = $this->urlInterface
->getUrl('customer/account/login');
return $this->resultRedirectFactory->create()->setPath($login_url);
?>
answered 4 hours ago
Sourabh Kumar Sharma
15111
15111
add a comment |Â
add a comment |Â
up vote
2
down vote
Try something like this
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You need to return the ResultRedirect
object inside your execute()
method
add a comment |Â
up vote
2
down vote
Try something like this
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You need to return the ResultRedirect
object inside your execute()
method
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Try something like this
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You need to return the ResultRedirect
object inside your execute()
method
Try something like this
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You need to return the ResultRedirect
object inside your execute()
method
answered 4 hours ago
George M
2965
2965
add a comment |Â
add a comment |Â
up vote
1
down vote
You have to redirection from execute(), in your code . You did not build Action class properly.
And your code it is missing this function.
public function execute()
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
add a comment |Â
up vote
1
down vote
You have to redirection from execute(), in your code . You did not build Action class properly.
And your code it is missing this function.
public function execute()
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You have to redirection from execute(), in your code . You did not build Action class properly.
And your code it is missing this function.
public function execute()
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
You have to redirection from execute(), in your code . You did not build Action class properly.
And your code it is missing this function.
public function execute()
return $this->resultRedirectFactory->create()->setPath('customer/account/login');
edited 4 hours ago
answered 4 hours ago
Amit Beraâ¦
54k1366157
54k1366157
add a comment |Â
add a comment |Â
up vote
1
down vote
Use below code
<?php
namespace VenorModuleControllerIndex;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use MagentoCustomerModelSession;
use MagentoFrameworkAppResponseHttp;
use MagentoFrameworkUrlInterface;
class Index extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkAppResponseHttp $http
)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
$this->_pageFactory = $pageFactory;
$this->_http = $http;
public function execute()
$login_url = $this->urlInterface->getUrl('customer/account/login');
$this->_http->setRedirect($login_url, 301);
$pageFactory = $this->_pageFactory->create();
return $pageFactory;
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
add a comment |Â
up vote
1
down vote
Use below code
<?php
namespace VenorModuleControllerIndex;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use MagentoCustomerModelSession;
use MagentoFrameworkAppResponseHttp;
use MagentoFrameworkUrlInterface;
class Index extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkAppResponseHttp $http
)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
$this->_pageFactory = $pageFactory;
$this->_http = $http;
public function execute()
$login_url = $this->urlInterface->getUrl('customer/account/login');
$this->_http->setRedirect($login_url, 301);
$pageFactory = $this->_pageFactory->create();
return $pageFactory;
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Use below code
<?php
namespace VenorModuleControllerIndex;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use MagentoCustomerModelSession;
use MagentoFrameworkAppResponseHttp;
use MagentoFrameworkUrlInterface;
class Index extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkAppResponseHttp $http
)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
$this->_pageFactory = $pageFactory;
$this->_http = $http;
public function execute()
$login_url = $this->urlInterface->getUrl('customer/account/login');
$this->_http->setRedirect($login_url, 301);
$pageFactory = $this->_pageFactory->create();
return $pageFactory;
Use below code
<?php
namespace VenorModuleControllerIndex;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppActionContext;
use MagentoCustomerModelSession;
use MagentoFrameworkAppResponseHttp;
use MagentoFrameworkUrlInterface;
class Index extends MagentoFrameworkAppActionAction
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppResponseRedirectInterface $redirect,
MagentoFrameworkUrlInterface $url,
MagentoFrameworkAppResourceConnection $resource,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCustomerModelSession $customerSession,
MagenticiansEvaluationModelEvaluationFactory $EvaluationFactory,
MagenticiansEvaluationModelEvaluation $eval,
MagenticiansEvaluationModelResourceModelEvaluationCollection $evaluationCollection,
MagentoFrameworkControllerResultFactory $result,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkAppResponseHttp $http
)
parent::__construct(
$context
);
$this->EvaluationFactory = $EvaluationFactory;
$this->_customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->resultRedirect = $result;
$this->_resource = $resource;
$this->_evaluation =$eval;
$this->_evaluationCollection = $evaluationCollection;
$this->redirect = $redirect;
$this->urlInterface = $url;
$this->_pageFactory = $pageFactory;
$this->_http = $http;
public function execute()
$login_url = $this->urlInterface->getUrl('customer/account/login');
$this->_http->setRedirect($login_url, 301);
$pageFactory = $this->_pageFactory->create();
return $pageFactory;
edited 3 hours ago
answered 4 hours ago
Ansar Husain
1,182216
1,182216
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
add a comment |Â
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
<b>Fatal error</b>: Uncaught Error: Call to a member function setRedirect() on null in /var/www/html/sajjada/app/code/Magenticians/Evaluation/Controller/Index/Index.php:123
â Developper Magento
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
did you do use MagentoFrameworkUrlInterface; in top and Http $http, in construnction and $this->_http = $http;
â Ansar Husain
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
sorry i forget to add $this->_http = $http; but even added this line there is no redirection to login page but error is gone so what s the problem can you please help me
â Developper Magento
4 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
Check post now i have updated code using your code in my answer use as it is
â Ansar Husain
3 hours ago
add a comment |Â
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%2f242273%2fhow-to-redirect-customer-from-controller-not-observer-to-login-page-magento-2%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