Drupal_bootstrap:Connect to Drupal

本文介绍如何使用drupal_bootstrap函数加载Drupal环境,并通过PHP脚本来访问Drupal数据库,获取特定节点的信息。示例代码展示了加载Drupal环境、执行全功能操作并打印节点内容的方法。

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>';
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值