I created Index.php controller for that at app/code/Vendor/Modulename/Controller/Index/ and add this below code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?php namespace Vendor\Modulename\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\View\Result\PageFactory */ protected $resultPageFactory; /** * @var \Magento\Framework\HTTP\Header */ protected $httpHeader; /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\HTTP\Header $httpHeader * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\HTTP\Header $httpHeader, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { $this->httpHeader = $httpHeader; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * Detect Mobile view or Desktop View * * @return void */ public function execute() { $resultPage = $this->resultPageFactory->create(); $userAgent = $this->httpHeader->getHttpUserAgent(); $isMobile = \Zend_Http_UserAgent_Mobile::match($userAgent, $_SERVER); if ($isMobile) { $resultPage->getConfig()->getTitle()->prepend(__("Mobile View")); // Mobile view logic add here } else { $resultPage->getConfig()->getTitle()->prepend(__("Desktop View")); // Desktop view logic add here } return $resultPage; } } |
You can add this above code in your controller or any file. You need to inject \Magento\Framework\HTTP\Header class into your construct.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62838632c387b324574817/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...