Load core to use in external script


I’m Kirby newbie, as a previous WordPress developer I’ve one question.

Is it possible to load Kirby core in an external script?

In my case I have an external PHP script to do some external tasks that doesn’t belong to Kirby, but I’d like to use the Kirby config file to load the parameters defined in there.

Is that possible?

Can I load only the Kirby core from an external script?


Should be possible with the same code that Kirby uses:


// load kirby
require(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');

$kirby = kirby();

// render
echo $kirby->launch();

You would have to adapt the path to the bootstrap file, of course.

Thanks for your help.

I’ve tried that solution but I always get empty results for config variables, this is my code:

require ‘…/…/…/kirby/bootstrap.php’ ;

$kirby = kirby();

// render
//echo $kirby->launch();

echo "DB NAME --> " . c::get(‘db.name’);

//To set db connection info
c::set(‘db.host’, ‘localhost:3306’);
c::set(‘db.user’, ‘root’);
c::set(‘db.password’, ‘root’);
c::set(‘db.name’, ‘my_db_name’);

Ah, sorry, the config file is only loaded during $kirby->launch().

So, I can’t do it? There’s no way to load config without launching the site?

What exactly are you trying to achieve? Can’t you make this a plugin so that the Kirby core is available by default?

OK, thanks, I’ll try it to implement it as a plugin.