1

I have a custom contenttype called posts, which has about ten records. Each of them is stored in bolt_posts table together with other Bolt-specific tables. I'd like to access a post with id = 1 in one of my custom php files. The problem is that the database for my application is separated from the database which holds internal Bolt tables. Is there a native Bolt API that I could use in order to query those tables? I've found this https://docs.bolt.cm/3.1/extensions/storage/queries, but I am not sure what directives I need to put in my php code in order to be able to run such commands. Thanks in advance!

Alex
  • 3,719
  • 7
  • 35
  • 57

2 Answers2

1

Assuming you're using composer to load Bolt into an existing application then this can be achieved by constructing an instance of a Bolt app.

All you need is a configuration, that takes the root folder of the Bolt site and then to initialize the app. For instance, assuming Bolt is accessible via autoload..

$config = new Bolt\Configuration\Composer('/path/to/bolt/root/');
$app = new Bolt\Application(['resources' => $config]);
$app->initialize();

That gets you the instance of a Bolt app and then you can follow the instructions in that documentation to query the Bolt db.

eg:

$record = $app['query']->getContent('pages/1');
Ross Riley
  • 826
  • 5
  • 8
  • I should've mentioned that my website is built with Bolt at its core, and that I am not using Composer. Given that I have a typical Bolt 3.0 directory hierarchy (i.e. `app`, `extensions`, `public`, `vendor`, etc.) at the root of my website, what would the correct path to the Bolt app be? – Alex Sep 04 '16 at 16:13
0

if you want to access the content from within an external application, you need to connect to the bolt database manually and fetch the data. Bolt's own storage layer can only be used when you work directly in Bolt (e.g. within an extension).

Phillipp
  • 1,425
  • 2
  • 12
  • 27