How to pass data from Controller to View Template files in Magento 2?

You can pass data from the Controller action to the Template files in Magento via Block Class.

You can’t directly pass controller data to view the template files but using the Block class you can achieve it successfully.

By use of the Magento interface, Magento\Framework\App\Request\DataPersistorInterface We are able to store data by key with the set(), get() method. Continue reading “How to pass data from Controller to View Template files in Magento 2?”

How to rename file programmatically Magento 2?

You can rename the file names in Magento by providing the source path and destination path.

I have tested the given functionality to rename the file names under the pub directory. You can do it for outside pub directory but you need to change __construct() method $this->directory argument value.

$this->directory = $filesystem->getDirectoryWrite(DirectoryList::PUB); Continue reading “How to rename file programmatically Magento 2?”

How to get current date time programmatically in Magento 2?

Magento 2 Fetch Current Date Time programmatically by use of the DateTime() method.

If you want to fetch the GMT Date time Check the link, Magento 2 GMT date time Format.

Just use the given code to display the current date and time from the system. Continue reading “How to get current date time programmatically in Magento 2?”