1. Go to this page and download the library: Download j-stam/magento2-shell library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$sql = 'SELECT * FROM your_table LIMIT 1';
$result = $this->connection->fetchAll($sql);
// or
$query = $this->connection->query('SELECT * FROM your_table LIMIT 1');
$result = $query->fetchAll();
$this->logger->error('Your error message');
$this->logger->info('Your info message');
...
$this->writeln('Your line');
$this->write('Your message')
$this->write(['Your message', 'Your other message'])
Example extends \Stam\Shell\ShellAbstract
{
protected $product;
/**
* Optional function, can be used for dependency injection
*/
protected function di(
\Magento\Catalog\Model\Product $product
) {
$this->product = $product;
}
public function run()
{
$this->writeln('Hello world!');
$this->logger->debug('Hello world!');
}
}
$shell = new Example();
$shell->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.