1

I have a static site with a drupal blog in a subfolder and I want to bring the latest posts into the homepage. I can run a drupal_bootstrap and then load the nodes I want. Is this an ok strategy? When is it appropriate to use drupal_bootstrap?

1

Check the doc of drupal bootrstrap: In order to bootstrap Drupal from another PHP script, you can use the following code:

define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

drupal_bootstrap($phase = NULL, $new_phase = TRUE)

Parameters

$phase: A constant telling which phase to bootstrap to. When you bootstrap to a particular phase, all earlier phases are run automatically. Possible values:

DRUPAL_BOOTSTRAP_CONFIGURATION: Initializes configuration.
DRUPAL_BOOTSTRAP_PAGE_CACHE: Tries to serve a cached page.
DRUPAL_BOOTSTRAP_DATABASE: Initializes the database layer.
DRUPAL_BOOTSTRAP_VARIABLES: Initializes the variable system.
DRUPAL_BOOTSTRAP_SESSION: Initializes session handling.
DRUPAL_BOOTSTRAP_PAGE_HEADER: Sets up the page header.
DRUPAL_BOOTSTRAP_LANGUAGE: Finds out the language of the page.
DRUPAL_BOOTSTRAP_FULL: Fully loads Drupal. Validates and fixes input data.

$new_phase: A boolean, set to FALSE if calling drupal_bootstrap from inside a function called from drupal_bootstrap (recursion).

Return value

The most recently completed phase.

Also check this: How to call drupal_bootstrap from custom file in subfolder?

| improve this answer | |
  • I was asking when is it appropriate, so I guess that it is always ok? – Andrew Welch Mar 11 '14 at 9:20
  • @AndrewWelch I guess its appropriate whenever you want to load drupal bootstrap from PHP script, there shouldn't be any problem of doing so, infact this the purpose of providing the option. – Ankit Agrawal Mar 11 '14 at 9:32
2

In order to bootstrap Drupal from another PHP script, you can use below code:

 define('DRUPAL_ROOT', '/path/to/drupal');
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

When ever you would like to call Drupal Functions or features outside of Drupal root you can use above code..

| improve this answer | |
1

Yes, when using Drupal functionality make sure you run the bootstrap. It's more risky to create/alter/query the database native as dependencies might get corrupt/lost.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.