Access SiteConfig data inside public/index.php


I have define a variable in admin settings, I want to access that variable inside public/index.php.

Is there any possibility I can access siteconfig configs inside public/index.php?


It’s quite an unusual thing to want to do anything inside index.php That file really is just setting up the application to deal with the request and nothing more.

What’s the big picture of what you need to achieve? There may be a better place to implement the functionality which already has all the access you need.

Thanks for the reply.

I have added this caching library (staticpublishqueue) and loaded inside index.php
here i want to enable this from admin settings.
I hope I’ve outlined my problem correctly.

hmm… OK.

The whole point of the additions to index.php when using Static Publisher is to avoid loading the Silverstripe application when you are using it, by delivering pre-rendered, static pages of content.

If you want to get access to siteconfig data, then you’d need to fire up the Silverstripe application for every request… which makes the static publisher a bit pointless (since you might as well just use some partial caching).

What’s the overall thing you’re trying to do… have it possible for a content editor to turn static publishing on and off from the CMS?

yeah seems a costly solution - even if we able to accomplish this.

require_once '../vendor/silverstripe/staticpublishqueue/includes/functions.php';
$requestHandler = require '../vendor/silverstripe/staticpublishqueue/includes/staticrequesthandler.php';

if (false !== $requestHandler('cache')) {
} else {
  header('X-Cache-Miss: ' . date(DateTime::COOKIE));

This is the code i want to put in ON/OFF condition.
I didnt find any enable/disable condition in CMS.
so i thought i can define a checkbox in admin CMS and use here in index file.

what else could be the solution. Please guide

Ultimately the config you’re setting is just some data in the database. You could write a raw SQL query for the db if you’re really intent on doing it that way.

You could also change where you’re storing that data - i.e. in your extension where you’re adding the “admin settings” (presumably a checkbox in SiteConfig), you could add a setter method such that when the value is set, it saves something in a file on the filesystem. Then, in index.php you just need to check that file.

Thank You for the good suggestion.

Here to overcome this problem i simply include a file insides index.php and creates a task.
The task will empty the file on disable and output the caching code inside that file on enable cache.
Thanks for the suggestions.