Posted by dreadstar on December 23, 2008 at 3:25pm
Newbie here stuck with a problem. Patulong naman sa mga gurus.
Im learning Drupal because the cms allows php code to be embedded into a story/page node. My php code uses some very often called functions all stored in a library file and called by my php code via the 'include' command.
Unfortunately, Drupal does not like the 'include' command and spits out an error pointing to the core file common.inc. Anyone knows how I can 'include' a php library file called by my php code?
More details can be seen at my post at http://drupal.org/node/346065
I didnt get an answer so I was hoping maybe a kababayan would point me to the right direction.
Thanks in advance.

Comments
Using Block?
if you consider this as an option..try to use block..i've already done skype and ym status message in my site and it works...
Thanks achilles085 for the
Thanks achilles085 for the recommendation. Unfortunately, I got a similar error that broke my test site.
Fatal error: Class 'FusionCharts' not found in W:\www\drupal\includes\common.inc(1547) : eval()'d code on line 3Still the 'include' statement causing the error and drupal pointing me to the common.inc file. I think I have to add my php library functions somehow to common.inc but I dont know how. simply adding them by brute force didnt work. I didnt expect it to work anyways ... 8-)
Did you try to include the
Did you try to include the whole path, instead of include('../folder/included-file.php') why not include('./site/all/module/folder/inside-folder/included-file.php').
Thanks Merto. Im sure its
Thanks Merto. Im sure its not a path problem. Even a simple test 'include' file with just an echo statement would break the code. Based on my searches on the www.drupal.org site on past queries, drupal (or even other competitior cms) will not readily accept 'include' statements in php codes (input format set to php codes). Has smething to do with having to register dependencies on a master file (which I am suspecting to be the common.inc file). However Im afraid my rudimentary programming skills will never achieve the proficiency of understanding how that works 8-)
are you talking about this?
http://www.fusioncharts.com
try the forum
http://www.fusioncharts.com/forum/Forum31-1.aspx
Good Luck and let us know.
Write a simple module
I know you want to avoid using a module but....one solution would be to create an empty module, put your php functions in there, then use the drupal api to call your functions.
If you're already familiar with php, then creating a new module is fairly straight-forward.
Check out the hook_form_alter() function, and hook_node_api():
http://api.drupal.org/api/function/hook_form_alter
http://api.drupal.org/api/function/hook_nodeapi
Got a work around solution
mgoltra - yes ive looked at the forum for answers. Ive also noticed that others have been trying to get fusioncharts t work with a cms and some with some success but not very successful or full implementation at all.
j.francisco - I may eventually have to look at building a module however as the saying goes ... "you most probably dont need to create a module ... if you do, then your probably doing it all wrong" ... 8-)
Ive found a work around solution though (albeit temporary). Ive totally abandoned using the php class libraries and started from scratch and looked at the javascript way. It works despite the spaghetti code (php insertions since I dont know javascript). Ive read though that everyone will end up hitting the wall concerning the limitations of the embedded data xml string sooner or later. I expect to have the same problem later when my test site gets deployed in the real world. But thats a problem I will worry later on.
Thanks everyone for the great help!
Try putting your libraries
Try putting your libraries in the drupal root directory. File system should look something like this:
drupal
/includes
/misc
/index.php
/<etc.>
/your_custom_library
/your_custom_php_file
Your php snippet doesn't works because php can't find your include files. Any include statement in the embedded php code should be relative to index.php
Thanks,
Tnx Jhef for the input ....
Tnx Jhef for the input .... but have you tried to access php libraries inside drupal via include statements? It just does not work or is inaccessible inside Drupal just as others have commented. I wish it was just a simple linking problem.
Actually, Im almost done with getting a working prototype site out. In case anyone is interested, the site generates charts in realtime within drupal accessing the data in mysql. As I have mentioned, Ive abandoned the direction of using php libraries and used javascript.
http://benchmark.liip.net
Lets see a competitive cms try generating those charts on their platform. Drupal rocks ... albeit its such a steep learning curve for computer illiterates like mwah.
certified newbie but Im learning something new every week ... 8-)
My coworker actually figured
My coworker actually figured it out as I was mulling over this too.
Do this, in your themes directory, create a new directory called "includes" then as your php files, make sure they have extension ".inc"
So:
/sites/all/themes/Your_theme/includes
And then create your files:
/sites/all/themes/Your_theme/includes/file-you-want-in-block.inc
Now, do this:
<? include "." . base_path() . path_to_theme() . "/includes/file-you-want-in-block.inc"; ?>
Don't know why it has to be like this, but it works :) Hope this helps you all
-Eric
www.bestcovery.com
Well done
This has been driving me crazy trying to figure it out. It used to work on Drupal 5 and some early versions of Drupal 6.
Well done for working it out and thanks for submitting it.
http://www.junglecreative.com
http://www.raynimmo.com
Sir
Sir esend7881@drupal.org,
Bro your a genius! It worked!
You just missed a dot on your code ... it should have been
<? include ".." . base_path() . path_to_theme() . "/includes/file-you-want-in-block.inc"; ?>
other than that ... it worked great!!!!!!!!!
Sorry I got confused. Where
Sorry I got confused. Where should I write
<? include ".." . base_path() . path_to_theme() . "/includes/file-you-want-in-block.inc"; ?>
I have also found this link which handles this through modules but I don't like it much, since I have a library.
adding php function
I am having the same problem.
I am having the same problem. I know you fixed yours. I am still getting the same error :
Fatal error: Class 'FusionCharts' not found in /home/content/a/n/p/xxxxxx/html/includes/common.inc(1685) : eval()'d code on line 7.
Could you provide details on how you fixed yours?
Thanks
I use fusioncharts
I use fusioncharts extensively in our offsite back office intranet. Basically php was a PITA and I ended up just using the javascript code. That basically circumvented the include function error. You can take a look at it here:
http://rtmsi.liip.net
username:visitor
password:visitor
Its under "benchmark" menu in the left nav menu.
Just simple uses of the chart. Just holler if you need help.
We can also use
We can also use http://api.drupal.org/api/function/drupal_get_path/5
<?phpinclude(drupal_get_path('theme', 'your_theme_name') . '/your_library_folder_inside_of_your_theme_folder/your_file.php');
?>
to avoid problem in case of
to avoid problem in case of changing theme, i suggest to create a "plugins" folder in "sites/all" and put all the libraries you need into.
Then include each file by calling
include (".." . base_path(). "sites/all/plugins/". FILENAME);
-
Very cool. Worked for me. Note that the extra dot caused problems for me though. Instead I used...
include (".".base_path(). "sites/all/plugins/".FILENAME);
Thanks again.
Confusing
Please can someone tellme the procedure esend7881 told.
Its confusing
The proper way to include module library files
These pages describe how and why to use the "module_load_include" function, instead of the PHP commands "include", "include_once", "require" or "require_once". One of the benefits is that "module_load_include" solves the path problem:
http://api.drupal.org/api/function/module_load_include/6
http://buildamodule.com/blog/the-correct-way-to-include-files-in-your-dr...
http://data.agaric.com/node/2856