I need to bootstrap Drupal. I have a php-file with all my functions and in one of those functions, I need to use a Drupal function which is located in the bootstrap.inc file.
Structure of the server:
(d) drupal (sd)includes (f)bootstrap.inc(d) scripts (sb)functions (f) functions.phpSo I need to include in a self-written function the "variable_set" function, located in bootstrap.inc.
A little piece of the function my college wrote (I'm terribly sorry, but I don't know how to format php on the forum. If someone does, please let me know so I can edit this mess):
function readxml()
{
echo "<br/>READING...<br/>";
$file = './config.xml';
$xml 开发者_Go百科= simplexml_load_file($file);
if($xml !== false)
{
foreach($xml->config->children() as $item){
$name = $item->getName(); // GETS CHILDREN UNDER 'CONFIG'
switch($name)
{
case 'website':
foreach($xml->config->website->children() as $kid){
$childname = $kid->getName();
switch($childname)
{
case 'theme':
if(inserttheme($kid)or die ('failed to insert theme<br/>')){
echo 'theme is installed.<br/>';}
break;
case 'slogan':
if(insertslogan($kid)or die('failed to insert slogan<br/>')){
echo 'slogan is installed.<br/>';}
break;
case 'sitename':
if(insertname($kid)or die('failed to insert name<br/>')){
echo 'website name is installed.<br/>';}
break;
}
}
break;
`
So, somewhere in the theme/slogan/name section, I have to call the variable_set function which is located in the bootstrap.inc file.
Somewhere I found this (again sorry for the non-formated text):
$drupal_directory = "/home/httpdocs/drupal"; // wherever Drupal is
$current_directory = getcwd();
chdir($drupal_directory);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
chdir($current_dir);
return;
I included it both in my function.php as well as in my final php-file (where all the functions are called) but no result... What am I doing wrong?
That code you found looks about right, what is exactly is "no result", are you getting errors or nothing or...? Also, where did you put it exactly? (If it is not in a function, you need to remove the last line (return))
Also, the proper way to fix this would be to integrate your custom code as a Drupal module, then you don't have to worry about stuff like this: http://drupal.org/developing/modules
Or if it is a CLI script, expose it as a drush command: http://drupal.org/project/drush
Answer to the question, just include the file inside the Drupal folder!
精彩评论