We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to use Faker for migration seeding?

I'm using Faker via Composer autoload and everything works fine in a controller, for example, since index.php loads config/loader.php file. However, Devtools solely loads config/config.php, hence Faker isn't available in my migration files. For the same reason, I can't use a model to insert data (models are autoloaded via config/loader.php as well).

How can I handle this? Can't require config/loader.php in my migrations, because it relies on config/config.php vars. Can specify it as config parameter neither, for the same reason.

edited Dec '14

Perfect, but instead of writing a bootstrap just for cli, I've made it work with web as well :-)

If anybody comes to here with a similar issue, the final command was:

phalcon migration run --config="app/config/bootstrap.php"

app/config/bootstrap.php file:


 * Read the configuration
$config = include "config.php";

 * Read auto-loader
include "loader.php";

 * Read services
include "services.php";

 * Composer autoload
include __DIR__ . "/../../vendor/autoload.php";

return $config;