Nicotine

Open source framework for PHP & MySQL

Downloads Page

/workspace/cli/ folder contains support for CLI scripts. It is divided into crons/ and scripts/ subfolders. The difference between scripts and crons is that crons runs periodically, whereas scripts are executed when you need, e.g. once, from the command line. In rest they are the same.

Running CLI scripts

Creating a CLI script example /workspace/cli/scripts/bar-script.php

<?php
declare(strict_types=1);

// Optional
namespace workspace\cli\scripts;

use 
nicotine\Registry;

$db Registry::get('Database');
d($db->getCustom(query"SELECT `first_name`, `email` from `staff`"params: [], fetchMode: \PDO::FETCH_OBJfetchAlltrue));

$proxy Registry::get('Proxy');
d($proxy->admin->model('StaffModel')->getMember(16));

Then:

cd workspace/cli

php console script:bar-script

There is no need to specify .php file extension. Also they can be placed into subdirectories, if you need. E. g. php console script:subfolder/bar-script

The folder /workspace/cli/scripts/logs contains error logs, if the configuration directive logErrors is set to true. They are keept per day and are gitignored. Please don't delete .keep file, it is needed for Git, to keep the folder, if you delete all logs.

Running CLI crons

Creating a CLI cron example /workspace/cli/crons/foo-cron.php

<?php
declare(strict_types=1);

// Optional
namespace workspace\cli\crons;

use 
nicotine\Registry;

$db Registry::get('Database');
d($db->getCustom(query"SELECT `first_name`, `email` from `staff`"params: [], fetchMode: \PDO::FETCH_OBJfetchAllfalse));

$proxy Registry::get('Proxy');
d($proxy->admin->model('StaffModel')->getMember(16));

Then:

cd workspace/cli

php console script:foo-cron

There is no need to specify .php file extension. Also they can be placed into subdirectories, if you need. E. g. php console cron:subfolder/foo-cron

The folder /workspace/cli/crons/logs contains error logs, if the configuration directive logErrors is set to true. They are keept per day and are gitignored. Please don't delete .keep file, it is needed for Git, to keep the folder, if you delete all logs.