By Arthaey on
I'm developing a module that uses JpGraph to draw some graphs. JpGraph works by generating an image, so you set an img tag's src to be some .php file. I'd like the graph to grab some data from the Drupal database, but the graph .php file isn't defined within any hook functions, so it doesn't have access to any Drupal functions.
Does anyone know how I could get this to work, short of 1) passing database values as parameters into the .php file (bad once I have many parameters to graph) or 2) directly connect to the database within the .php file, thus bypassing the standard db_query code? Neither option sounds that great, and I imagine other modules must come up against similar problems...
Comments
Database connections
I think you can use something like include('path/to/bootstrap.inc'); to accomplish this, but I'd look up the instructions for bootstrapping.
Dave
Including bootstrap.inc works, thanks!
At Dave's suggestion, I searched for info on bootstrapping. Another forum thread suggested looking at the Devel module for example code. And the documentation for drupal_bootstrap() says,
Below is what I got to work, from the directory drupal/modules/mymodule/script.php:
If there are issues with using
chdir()like this, please let me know.getting the full environment ..
here's some additional notes on how to get the full environment: http://drupal.org/node/70006
and Drupal functions
Hi Works fine this solution.
I can get data from my database. nice!
Is it possible call Drupal function into php file?
Something like:
Regards
Once you are bootstrapped,
Once you are bootstrapped, you can call any drupal function
ok
So Help me with this
Drupal node-form render is slow. (with hundreds of terms and Super_Select module).
So I'm thinking do this hack.
in my page.tpl.php I will have
in page-mycustomccktype.tpl.php I will have a
What I am trying to do is in "page-cckajax.tpl.php" tell to Drupal.
that this page is in node/add/myccktype
So I tried
NOT WORKING I tried lot of things
How can I force the path to page-cckajax.tpl.php? (this page will load with AJAX) Every time run index.php
You can see I will let my slow node-form run with ajax.
Or better I will run page-mycustomccktype.tpl.php and behind the scenes I will run "page-cckajax.tpl.php"
I will let my user fill a simple container with title and body and after this using Jquery I will redirect everything to next step, the true form (load from page-cckajax.tpl.php) and finnaly user could fill images and categories. And it is done. Will be amazing.
Two big problems
1) I need tell in page-cckajax.tpl.php the correct path and avoid index.php. like I said
2) I need tell to Drupal that the form from node/myccktype is same from node/add/myccktype or something like that
So
So I would like to know if is possible tell to drupal that 'page-cckajax.tpl.php' is in node/add/myccktype
Is it possible? In other word I am trying pass argument. Where argument is the path. I have two chances one in page-cckajax.tpl.php other in page-nodeaddmyccktype.tpl.php
Because Drupal understand that 'page-cckajax.tpl.php' is in 'node/' directory.
So drupal could print $content. Other chance is create a module and try print theme_mycck but still not working. I dont know but I cant invoke this theme_mycck from my module in 'page-cckajax.tpl.php'.
Regards
Unable to access DRUPAL database from outside Drupal
Hi,
I am unable to get the following code to work (to enable access to DRUPAL's database). On running the script nothing happens. Apache error log pasted below. Apparently some of the code in bootstrap.inc does not execute completely for some reason.
Would appreciate advice. Thanks
Script - all_nodes.php as below
<?php
chdir('C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/drupal78');
include_once('./includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSRTAP_DATABASE);
$result = db_query('SELECT nid, title FROM {node}');
foreach ($result as $row) {
echo $row->title . "
";
}
DRUPAL Stack - Windows 7/ Apache 2.2.x/ PHP 5.3.8/ MySQL/ DRUPAL 7.8
Apache error log -
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP Stack trace:
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP 1. {main}() C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\all_nodes.php:0
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP 2. drupal_bootstrap() C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\all_nodes.php:7
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP 3. _drupal_bootstrap_configuration() C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\drupal78\\includes\\bootstrap.inc:2071
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP 4. drupal_settings_initialize() C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\drupal78\\includes\\bootstrap.inc:2183
[Tue Jan 24 13:03:51 2012] [error] [client 127.0.0.1] PHP 5. _drupal_error_handler() C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\drupal78\\includes\\bootstrap.inc:720