Get directory location on Magento 2

<?php

	namespace Vendor\Module\Location;

	use Magento\Framework\App\Filesystem\DirectoryList;
	 
	class YourClass implements AnotherClass{

		protected $filesystem;

		public function __construct(
			DirectoryList $filesystem
		){
			$this->filesystem = $filesystem;
		}   

	    public function foo(){
	    	$pub = $this->filesystem->getPath('pub'); //pub can be changed into other folders
	    }
	}

?>			
John Perri Cruz

About the Author

John Perri Cruz was born in the Philippines, at the cold month of december. (Not cold enough cause Philippines is a tropical country.)

He's currently working as a Fullstack Web developer and when not sleeping, he can be found in coffee shop most of the time.

He gained his experience and skills by making and developing websites and systems for various individuals. He is well equipped with different Web programming languages and tools.

Connect :


Buy me a cup of coffee :

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*