Skip to content
Christian Münch edited this page Sep 15, 2013 · 4 revisions

Helpers

The Symfony Framework offers a Helper System. http://symfony.com/doc/current/components/console/introduction.html#console-helpers

n98-magerun comes with a list of special helpers for the command line.

Database Helper

Run DB-Query:

$db = $this->getHelper('database')->getConnection($output);
$db->query('DELETE FROM foo');

Get all tables:

$tables = $this->getHelper('database')->getTables();

Check MySQL Privileges:

$hasPrivileges = $this->getHelper('database')->mysqlUserHasPrivilege('select');

Get MySQL Connection String (for external MySQL cli client)

$connectionString = $this->getHelper('database')->getMysqlClientToolConnectionString();

Get PDO DSN:

$dsn = $this->getHelper('database')->dsn();

Return value of a MySQL variable:

$waitTimeout = $this->getHelper('database')->getMysqlVariableValue('wait_timeout');

Parameter Helper

Ask Store

Evaluates the parameter "store". As third parameter you can specify a different argument name if it's not the recommended name "store".

$this->getHelper('parameter')->askStore($input, $output);

Ask for website

$this->getHelper('parameter')->askWebsite($input, $output);

Ask for Email

$this->getHelper('parameter')->askEmail($input, $output);

Ask for Password

$this->getHelper('parameter')->askPassword($input, $output);

Table Helper

$table = array();
$table[] = ('line' => '1', 'firstname' => 'Peter');
$table[] = ('line' => '2', 'firstname' => 'Lena');
$this->getHelper('table')->write($output, $table);

TwigHelper

Renders a Twig Template. See Twig for configuration options.

$this->getHelper('twig')->render('template_name.twig', array('var1' => 'value1');

Render Twig code directly.

$this->getHelper('twig')->renderString('{{description | lower}} {{var1}}', array('var1' => 'value1');