Categories


Archives


Recent Posts


Categories


Quickly Search all Magento 2 Controller Files

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Here’s a fun pestle command I forgot about.

pestle.phar magento2:search:search_controllers

This command accepts a file path as a single argument, searches through the specified folder for anything that looks like a Magento controller file, and then displays that controller file’s execute method along with its relative file path.

Pipe the resulting output to a file or text editor, and you can quickly search through all Magento’s controller files. For example, today I forgot the syntax for adding a custom handle to a layout update XML file – but with magento2:search:search_controllers the syntax was and a “Ctrl-F handle” away.

$ pestle.phar magento2:search:search_controllers
//...
vendor/magento/module-backend/Controller/Adminhtml/Denied.php
--------------------------------------------------
function execute()
{
    if (!$this->_auth->isLoggedIn()) {
        /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setStatusHeader(403, '1.1', 'Forbidden');
        return $resultRedirect->setPath('*/auth/login');
    }
    /** @var MagentoBackendModelViewResultPage $resultPage */
    $resultPage = $this->resultPageFactory->create();
    $resultPage->setStatusHeader(403, '1.1', 'Forbidden');
    $resultPage->addHandle('adminhtml_denied');
    return $resultPage;
}  
//...

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 28th February 2017

email hidden; JavaScript is required