Questions tagged [controllers]

Denotes questions about controllers and action methods

Filter by
Sorted by
Tagged with
43 votes
1 answer
7k views

Difference between /Controller and /controllers

A question I've been meaning to ask for ages, more theoretical than anything else. I'm fully versed in developing Extensions using the normal Magento module file structure. I've noticed though when ...
thebluefox's user avatar
34 votes
5 answers
58k views

Magento 2: How to get controller, module, action and router name?

Magento 2: How to get controller, module, action and router name?
Bhavik's user avatar
  • 1,240
30 votes
2 answers
2k views

Why c is lowercase in controllers of Magento?

Why is c lowercase in controllers folder name? Whereas Model, Block and Helper are starting with an uppercase letter?
Muthu's user avatar
  • 303
23 votes
5 answers
33k views

Send data from the controller to phtml

I have this controller: ... public function insertAction() { $something = 'testcase'; $this->loadLayout(); $this->_title($this->__("the title")); $this->renderLayout(); } ....
Bob van Luijt's user avatar
20 votes
5 answers
65k views

How to get media directory path in a phtml file in magento 2?

Used the below method in order to get the media directory path, but it returns an error. $om = \Magento\Core\Model\ObjectManager::getInstance(); $directoryList = $om->get(\Magento\App\Filesystem\...
Rita Jose's user avatar
  • 1,840
19 votes
3 answers
16k views

Magento 2: rewrite controller

how can i rewrite a controller (that's actually an action) in Magento 2? I tried, as instructed here like this: I have my own module called Namespace_Module with a di.xml file, that is taken into ...
Marius's user avatar
  • 198k
13 votes
5 answers
10k views

Why can't I inject the ProductRepositoryInterface in Magento 2?

I have a controller action into which I would like to inject the product-repository namespace Nosto\Tagging\Controller\Export; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Store\...
Mridang Agarwalla's user avatar
12 votes
4 answers
21k views

Magento2 - Custom Controller throws error

I created a module shown in this post. But my own controller doesn't work. I've got this error message: Recoverable Error: Argument 1 passed to MP\MyModule\Controller\Index\CheckUserName::...
ClassMP's user avatar
  • 1,793
12 votes
1 answer
49k views

How to make a simple ajax call in Magento 2.1.0

I have added a simple button in one of my phtml file. <input type='button' name='emq_zip_btn' class='emq_zip_btn' value='Go'> I have added one custom js file ("emq.js") from a custom module (...
vedu's user avatar
  • 857
12 votes
1 answer
18k views

How to override the controller AccountController

I need to override a method Controller Core/Mage/Customer/controllers/AccountController.php and add a new method. Since this controller to edit is wrong - it should be overridden. According to ...
Nice to see you's user avatar
11 votes
1 answer
17k views

Change page title in controler or block

I have found two ways for changing page title and I don't know which one I should use. 1. Override prepareLayout() in block protected function _prepareLayout() { $this->pageConfig->...
Bartosz Kubicki's user avatar
11 votes
1 answer
4k views

How do I make my custom module pages use SSL?

I've created a Module with some pages and I'm wondering how do I force this pages to use SSL on the url, like the customer login page. Not all of the pages need it, but some do. What comes to mind (...
Vic's user avatar
  • 1,424
11 votes
1 answer
699 views

Using Reserved Words in Magento 2 URLs

Is it possible to create a module in Magento 2, using standard routing, that responds to a URL in the form of http://magento.example.com/namespace_module/return/index That is -- a URL where the ...
Alana Storm's user avatar
  • 44.4k
11 votes
2 answers
5k views

How to get all children blocks in controller Magento 2?

I have to get all children block in controller using parent block name or layout Magento 2. Thanks in advanced.
Dharmendra Jadav's user avatar
10 votes
1 answer
7k views

Magento 2 : Modal Popup using Ajax

How to use model popup using ajax? Can any one help for this. Here below my code. How can i apply in this code model popup? And also post data get in popup. How it possible? app/code/Vendor/Complany/...
Payal Patel's user avatar
  • 1,511
10 votes
1 answer
988 views

The purpose of the http verbs interfaces

In Magento 2.3 there are some interfaces for all the http verbs Magento\Framework\App\Action\HttpPostActionInterface Magento\Framework\App\Action\HttpGetActionInterface, ... All of them are empty ...
Marius's user avatar
  • 198k
9 votes
3 answers
10k views

Creating custom module in magento2 show fatal error

I working on creating custom module in magento 2, but it's not working. Could you please suggest me where i went wrong?. My module code: app/etc/config.php: 'modules' => array ( '...
Ramesh's user avatar
  • 91
9 votes
4 answers
12k views

magento2.3 controller won't handle post method

This is something I used to be able to do in 2.2, but in 2.3 I can't. A simple controller to handle a POST method, and only receive and send application/json content type. It works for GET/PUT ...
Mac A.'s user avatar
  • 280
9 votes
1 answer
7k views

What are the Dispatch/Execute() functions and how do they work?

I would like an explanation of the dispatch and execute functions, the differences between them, when they are/should be used and how. Please limit your answer to Magento 2
LM_Fielding's user avatar
  • 1,533
8 votes
3 answers
40k views

Magento2 - How to get JSON response from Controller [closed]

I've created my custom controller and I want to return the result formated with JSON. I always get a JSON parse error "JSON.parse: unexpected character at line 1 column 1 of the JSON data" and the ...
ClassMP's user avatar
  • 1,793
8 votes
2 answers
21k views

How to get block method in controller?

My block file path is app\code\local\Company\Modulename\Block\Product\View\View.php In this file method name is getId() Now how to call call this method in controller?
ND17's user avatar
  • 5,181
8 votes
1 answer
28k views

Reliable way to redirect to last page

Is there a reliable way in magento to redirect to the last page. I have a small form that i want to redirect to the previous page if an error occurred. The form sits on the product page and ...
Marty Wallace's user avatar
8 votes
2 answers
21k views

How to get RefererUrl in magento 2 observer?

How to get RefererUrl (source page url) in Observer file? Actually by using this; $this->_redirect->getRefererUrl(); I am getting Referer Url in magento 2 controller file.But in Observer file ...
shankar boss's user avatar
  • 1,453
8 votes
2 answers
8k views

Magento 1 : how to override/rewrite a core controller class?

Note: This is intended as a canonical question that fully explains how controller rewrites work and can be used as duplicate target for more specific "How do I override controller X" or "Why does my ...
Raphael at Digital Pianism's user avatar
8 votes
3 answers
37k views

Magento 2 - Send form data to Controller using AJAX and return Result to PHTML

I am working on a simple custom module, where user can input height and the weight/BMI will be shown as output on form submit. The page where user enters input is Calculation Page while output is ...
Slimshadddyyy's user avatar
7 votes
2 answers
15k views

How to call a controller action outside magento?

We can create php scripts which runs outside magento. And also use magento functionalities by using the following code snippet in it. define('ROOT', ''); $mage_php_url = ROOT.'app/Mage.php'; ...
Sukeshini's user avatar
  • 9,955
7 votes
5 answers
29k views

Magento checkout - getting custom attribute value

I am working in the OnepageController.php What I needed was in the checkout process was to get values of some customer created attributes for the products in the current order. I have been able to ...
user1669256's user avatar
7 votes
3 answers
19k views

Magento 2: How to get data from controller to block/view

I am looking for the right flow of data of how Magento wants me to do it. I have some data which I want to pass to the view. How do I do this the right way? I saw the following answer for Magento 1.x ...
Akif's user avatar
  • 1,531
7 votes
4 answers
13k views

Call action after "Save Config" was clicked in the admin

How can I call an action of my controller in a custom module after "Save Config" was clicked in System --> Configuration --> Catalog? (image) Settings of my module are inside that section, and I need ...
zitix's user avatar
  • 2,192
7 votes
1 answer
7k views

magento 2 run function on every page

I have a function that retrieves a visiting user's country name by doing an ip lookup. I currently have this function running through the execute method in my module's controller. The problem is ...
Xenocide8998's user avatar
  • 1,772
7 votes
1 answer
7k views

Dynamic create block in magento 2 and send as ajax call response?

I want replacement of following in magento 2.x $block = $this->getLayout()->createBlock('customer/form_login')->setTemplate('persistent/customer/form/login.phtml'); $this->getResponse()-&...
Manish's user avatar
  • 3,106
7 votes
2 answers
17k views

Override a controller in Adminhtml

Currently I'm trying to override the GroupController of Mage_Adminhtml_Customer so I can add some code for saving my custom field in the Customer Groups menu. As you can think it doesn't really work ...
HamuSumo's user avatar
  • 135
7 votes
3 answers
18k views

Magento 2 - Ajax is not calling Controller

I tried to make a simple ajax-call to my controller. Somehow I don't get a valid response. MyCompany/MyModule/Index/GetAjax.php namespace MyCompany\MyModule\Controller\Index; class GetAjax extends ...
TrytoFly's user avatar
  • 634
7 votes
2 answers
15k views

Form Key Value in template and controller

The following function is used to get the form key in templates with type hidden. My customerController.php does not validate the form key with the method _validateFormKey(). When I echo the following ...
Muhammad Saeed Khan's user avatar
7 votes
3 answers
12k views

Custom Block "Invalid Block Type"

I have a custom Block which I'm now trying to break into two sepparate blocks. Here's my folder structure (on app/code/local/MyNamespace/CustomerDashboard): Since I want to break the functions of ...
Zed_Blade's user avatar
  • 255
7 votes
2 answers
9k views

Overriding a core controller's preDispatch method

I need to override a core controller's preDispatch method. The core controller inherits from Mage_Checkout_Controller_Action, which itself has a preDispatch method that needs to be called. Since I'm ...
Jeff Lambert's user avatar
7 votes
1 answer
806 views

Can Virtual Types be used as controllers?

This is more of a curiosity than a "need". I have a few controller actions that do exactly the same thing, just some parameters differ. I'm trying to reduce the amount of code I write and have one ...
Marius's user avatar
  • 198k
7 votes
2 answers
3k views

"We can't save the customer" error after Migration - Magento 2.3

I have migrated store from Magento 1.7.0.2 to Magento 2.3. When i Create the customer it shows me error "We can't save the customer." I have checked log file and i can see log, "Class Magento\Eav\...
Sunny Rahevar's user avatar
7 votes
1 answer
1k views

Magento 2: Why Does My Custom Controller Generate an Interceptor?

I recently created a basic routing configuration for a test module <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/...
Alana Storm's user avatar
  • 44.4k
7 votes
2 answers
2k views

AccountController override not working on new Action and doing 302 redirection

I am try add new action on AccountController Now: AccountController is override properly But it is whenever hit new Action (ajaxLoginPostAction) is redirect to 302. I add ajaxLoginPost() as open ...
Amit Bera's user avatar
  • 77.5k
7 votes
2 answers
3k views

How to avoid redirection to "enable-cookies" page during controller unit test?

I'm doing a very simple controller test using Ecomdev_PHPUnit: class Foo_BarWishlist_Test_Controller_IndexController extends EcomDev_PHPUnit_Test_Case_Controller { /** * @test * @...
Alex's user avatar
  • 13.8k
7 votes
1 answer
19k views

Magento + JQuery + Ajax - How do I reload just parts of my custom Module instead of the whole Block?

I was just recently given the task to create a simple Product configurator for our Magento Template in 5 days, where you can choose some attributes and it calculates the price for you, fades over a ...
ericstumper's user avatar
7 votes
5 answers
5k views

Update price in checkout page without refresh Magento 2

I have a controller where I apply some discount on the checkout page. Now, I can see the price change just after I refresh the page. I search for a solution, to refresh the price using a Js file. ...
Alin Lupoiu's user avatar
  • 2,662
7 votes
0 answers
106 views

How to do the same controller action to create an image for one button but not for another?

We are calling same controller action for 2 buttons for create product pro-grammatically and assign a custom image for that product. 1. create - custom image uploading for newly created product 2. ...
raj's user avatar
  • 69
6 votes
3 answers
28k views

Retreive and return response from controller in magento2

I have a problem in which I'm making an AJAX call to a controller. But, I am not able to check whether it is working or not. I also want to return data in response. But, it keeps throwing some errors. ...
Abhishek Dhanraj Shahdeo's user avatar
6 votes
2 answers
18k views

Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom module

I think my issue might have to do with dependency injection, which I'm still trying to grab the concept. What I would like to do is to be able to get the URL using getUrl() function from Magento\...
frostshoxx's user avatar
6 votes
2 answers
4k views

Magento\Framework\ObjectManager\ObjectManager given

I get the following when using my controller through a front end route. Fatal error: Uncaught TypeError: Argument 1 passed to Namespace\Module\Controller\Index\Index::__construct() must be an ...
Tyler's user avatar
  • 273
6 votes
6 answers
11k views

Programatically clear the cart of a logged-in user

TL;DR When a customer is logged in, Mage::getSingleton('checkout/session')->clear(); doesn't clear their cart. I need something that will. I've asked this as part of another question, but i ...
Matt Flamm's user avatar
6 votes
3 answers
3k views

Magento 2.2.5 : Cant go to execute() in Controller

I'm doing a simple CRUD custom module after this module C:\xampp\htdocs\magento\vendor\magento\module-cms\Controller\Adminhtml\Page\Save.php and I have a controller to save/create/add the "students" ...
fudu's user avatar
  • 1,278
6 votes
3 answers
6k views

What is the purpose of isAllowed method and when It is called in Magento 2?

I have seen that below method. protected function _isAllowed() { return $this->_authorization->isAllowed('Custom_Module::moduleslider_banners'); } What exactly it will do? Will it check ...
Jackson's user avatar
  • 9,909

1
2 3 4 5
20