Page 5 - Magento 2 Development
All PHP programmers are familiar with the superglobal variables such as $_GET, $_REQUEST, $_POST, but their direct use is not allowed according to Magento2 code standards. So don't use them in your Magento 2 projects, especially if you want to pass the code Technical Review on the Magento Marketplace.
So what methods should be used?
To get data from the query, use the following methods:
getParam($key, $default = null);
getParams();
getPostParam($key, $default = null);
getPost();
In Magento 2, one of the new properties is Magento 2 Virtual Type. What are they for?
Imagine that you already have a class A available:
namespace VendorName\ModuleName\Model
class A
{
protected $arg1;
protected $arg2;
protected $arg3;
public function __construct(
Argument1 $arg1,
Argument2 $arg2,
Argument3 $arg3
) {
$this->arg1 = $arg1;
$this->arg2 = $arg2;
$this->arg3 = $arg3;
}
}
And you need to create a class B, which will be inherited from A. However, it must take another argument as $arg2. To do this, you will create a new PHP file for class B:
Use the following code to insert the template block in WYSIWYG:
Before you install Magento 2, make sure that the webserver (such as LAMP) and Elasticsearch are configured and meet Magento 2 requirements.
Install the virtualhost script for the LAMP server, and create a new virtual host dev.mymagento.com, run the command:
virtualhost create dev.mymagento.com
Open this link in your browser and make sure you can see the content, not the error.
Download the archive with the latest version of Мagento 2. When downloading, you can select the "Include sample data" option, so that after you install Magento 2 test products and categories are available in the store.
Once you download the archive, place the folders and files from it in your domain directory /var/www/devmymagentocom.
Edit the virtual host domain configuration file, run the command:
gedit /etc/apache2/sites-available/dev.mymagento.com.conf
and change the string
DocumentRoot /var/www/devmymagentocom
to
DocumentRoot /var/www/devmymagentocom/pub
The pub folder must be the root one for the webserver.
After saving the changes, do not forget to restart the webserver, run the command:
service apache2 restart
Start installing Magento 2.