For testing purposes, or for executing Drupal-related operationsbut from a PHP script that runs outside of Drupal, I often createindependent PHP files that are not meant to be Drupal modules butstill require access to Drupal’s database, functions andmodules.
Using the function drupal_bootstrap,located within includes/bootstrap.inc, your script can load Drupaland make all of Drupal’s functionality accessible to yourscript.
Common Usage
For access to the Drupal database layer only:
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
For access to all modules and functions:
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Here is an example PHP script that loads Drupal in order to gainaccess to a Drupal node:
//set the working directory to yourDrupal root
chdir('/home/public_html/drupal/');
//require the bootstrap include
require_once './includes/bootstrap.inc';
//Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//(loads everything, but doesn't render anything)
//display a node
print '<pre>';
print_r(node_load(12));
print '</pre>';
本文介绍如何使用drupal_bootstrap函数加载Drupal环境,并通过PHP脚本来访问Drupal数据库,获取特定节点的信息。示例代码展示了加载Drupal环境、执行全功能操作并打印节点内容的方法。
397

被折叠的 条评论
为什么被折叠?



