I have Drupal 7 site which is working fine. I added a custom PHP page to my site in the root directory of it. I want to extend the Drupal application functionality to that one page so that I can have access to the different Drupal classes and basically extend Drupal through my page. What includes do I need at the top of my page to be able to access the Drupal application as if I were within the Drupal site?
The only file you need to include is '/includes/bootstrap.inc', but you also need to define the
It's exactly the same code that you'll find in the standard index.php file, minus a call to | |||||||||
|
Even though Clive's answer answers your question correctly, I'd still like to present the point of view that while what you're doing is not wrong per se, it's not a very good pattern as all custom code in Drupal is designed to reside under sites/all. The correct way to go about this is to have a custom module, that implements the horribly misleadingly named hook_menu -hook. I'll omit the details of creating and enabling a custom module as there's plenty of references out there for that, but this is what you need to do in your module that I'll call custommodule :
This is pretty much the bare minimun example and just hook_menu has enough options to tweak access, url parameter passing, cache handling etc to take care of most any scenario necessary. Yes, this is a couple of steps more work than what you were doing, but is far cleaner, more future proof and keeps all code where it's supposed to be. It's also quite a bit better aligned with how Drupal expects custom stuff to interact with it, so your page won't break if Drupal changes the way it bootstraps for some reason. | |||
|