I'm transferring a site into drupal but its going to take a really long time.

Meanwhile, new pages that are created are now using drupal.

I created a view/block to display recent pages from a node in the sidebar and use this code to display:

<?php
$view = views_get_view('viewname');
print $view->execute_display('default', $args);
?>

Works great for the Drupal pages, but (as the sidebar shows up in non-drupal pages) I get this error:

Fatal error: Call to undefined function views_get_view() in /home/content/xxx/html/sidebar.php on line 92

I suppose its not reading the drupal database or whatever, is there a way to fix that?

Comments

matt blaine’s picture

You'll need to include a file to be able to use the drupal api and call drupal_boostrap(

Check to your path on the include I just put that in as a possible path 'includes/bootstrap.inc

include_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

http://api.drupal.org/api/function/drupal_bootstrap/6

mattwmc’s picture

Thanks for the reply.

So are you saying to use this?

<?php
include_once '/home/content/xxx/html/cms/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$view = views_get_view('viewname');
print $view->execute_display('default', $args);
?>

However, I get an error:

Warning: require_once(./includes/cache.inc) [function.require-once]: failed to open stream: No such file or directory in /home/content/xxx/html/cms/includes/bootstrap.inc on line 1009
matt blaine’s picture

Not sure but seems like bootstrap is running and drupal starts to load but is confused by its path which is no longer what it expects

You may have to -- before calling drupal_bootstrap

set_include_path('/home/content/xxx/html/cms');

or see http://drupal.org/node/94077

mattwmc’s picture

That's what I thought as well.

This is the line (1009) in the boostrap.inc the error is referring to (I think)

require_once variable_get('cache_inc', './includes/cache.inc');

I wonder if its because I don't have drupal installed in the root (/cms/drupal).

mattwmc’s picture

Maybe I can bump this...anyone?

matt blaine’s picture

Sorry this got buried on me.

Before loading bootstrap you could try and set your include path so that when bootstrap load it will be able to include its includes

set_include_path('/home/content/xxx/html/cms');
include_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
mattwmc’s picture

Thanks for replying.

Doesn't matter now as I moved drupal into the root and am in the process of moving everything over - if only I could get into Drupal Admin, lol.

That's for the other thread, though, lol.

anyr’s picture

I need to do the same thing, if anybody knows how. I want to display a block on our display screens, rotating news and events.

I've got as above,

set_include_path('/path/htdocs');
include_once '/path/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$view = views_get_view('events');
print $view->execute_display('default', $args);

It falls over at drupal_bootstrap, the includes seem to be ok. Any help gratefully received!

summit’s picture

Subscribing, interested in this also!
Greetings, Martijn

mattwmc’s picture

Yeah, I still can't get it to work with any of the above.

Anyone?

dpardo’s picture

The solution is to execute a chdir first:

$base_dir = $_SERVER['DOCUMENT_ROOT'];
chdir($base_dir);
require_once "./includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
mattwmc’s picture

Awesome!

That's it!

However, I get a conflict (I think) with a require_once code I have to show forum posts from Simple Machine Forums on some pages:

require_once('/home/content/xxxx/html/forum/SSI.php');

ErrorL

Fatal error: Cannot redeclare db_error() (previously declared in /home/content/xxxx/html/forum/Sources/Errors.php:116) in /home/content/xxxx/html/includes/database.mysqli.inc on line 193

Is there a work around? No big deal for me if there isn't, I can eliminate the SMF code. Thought I would ask.

mattwmc’s picture

Spoke to soon.

For some reason it is changing the links and adding to it.

For me its adding /reviews/ to all links.

Example - link is supposed to be /news/newsoftheday but coming out /reviews/news/newsoftheday

anyr’s picture

Thank you so much that works great!

It does rewrite the drupal url to be whatever directory I call the script from, but I can rewrite the links or remove them as it's only for display screens.

w00t!

mattwmc’s picture

Yes, I think that is whats happening for me.

Its writing the url as if its in the directory of the page the code is found on.

Is there a fix to print the exact url?

For example, if I put the code on a page inside the 'articles' directory it will print the url as /articles/node
instead of /node.

Cablestein’s picture

This worked like a charm for me, many thanks. I feel I just opened up a door to a huge new dimension.

ALSO: Make sure "DOCUMENT_ROOT" is in big caps. Small caps doesn't work for me.

I'm on Windows Server 2003, Drupal 5, PHP 5.2

Cablestein’s picture

Another tip, you may need to chdir again to get back to the proper working directory so things like image paths may work properly.