Posted by tcjohans on July 25, 2006 at 12:42am
Hi,
I wonder if there is a list available somewhere of "Drupal environment variables", or variables (or arrays or objects) made available by Drupal to PHP scripts.
For instance, I noticed that there is a global $user object available and that $user->uid and $user->name (or maybe uname?) gives the current user´s user id and username respectively.
Thanks,
Thomas
Comments
I believe this is a critical issue for Drupal
I was about to post this ;) And other people are asking the same question.
There needs to be a serious discussion that hopefully will result in an addition to api.drupal.org.
Wouldn't it be fantastic, and far more intuitive, to be able to type (for instance) $mid into the API search and have something like
------ example starts
$mid - The menu ID of a menu item
Used In These functions.
menu_get_item
etc.
etc.
And maybe even some trace code you would use to find the $mid of the page you were on.
----- example ends
I think the basis for this already exists. I've been hunting around for the last hour or so and found the following resources that I hope help people in the meantime.
But a searchable resource (Or even just a pdf ) would be invaluable. It would IMHO help decrease infamous Drupal learning curve which logically would increase uptake and also empower more people to take an active roll in Drupal's development.
I am a professional web developer. I have been working with Drupal on and off for 6 months on some big sites that required allot of customisation. I sincerely believe that this is a critical issue that needs to be addressed.
Maybe at DrupalCON Europe?
Ben W
install devel module
click variable viewer.
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
That's handy but...
Cheers Steven.
The object structure tab is also very helpful.
But I don't think this (excellent) module solves the issue I'm trying to address.
Devel exposes drupal variables and their current value. It does not explain (clearly and simply) what they do or how they fit into Drupal.
Ben W
that's for
http://api.drupal.org/
The stuff just changes so fast and depends on modules installed, activated, etc. Feel free to start adding handbook pages to the handbook but on the fly interpretation has been found the most effective by people playing with Drupal over time.
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
Good point and good suggestion but...
I was thinking of just documenting core install (and maybe image.module) variables. If we come up with a good standardized way for doing this then it would make sense for the module developers to document any variables that their modules add.
Adding handbook pages is a good suggestion. But because I don't have a good understanding of the drupal variables I will make mistakes in the initial drafts of the document. So I wouldn't want to make handbook pages straight away. That's why more senior developer/s would need to proof it. I think it would have to be a iterative process.
Steven, when you say
Is that in response to me saying
Because that's exactly my point. I believe http://api.drupal.org/ should explain (clearly and simply) what the core variables do and how they fit into drupal in the same way that it currently explains what the core functions do.
Ideally the input fields at http://api.drupal.org/ would read "Function, file, variable or topic name"
Is this such a silly idea?
Ben W
I'm willing to start this off
Look I know the experienced Drupal developers are (rightfully) sick of newbies demanding that they solve all their problems.
Why should you have to write documentation? We all hate writing documentation!
So I'm willing to start writing the thing. If someone knowledgeable is willing to proofread it.
Ben W
What about a forum to collect this info bit by bit
What about having a forum or similar venue where people who know some portion of the relevant environmental variables/arrays/objects could post what they know (listing the items, and for each item info of what data it contains, and maybe also mentioning the instruction through which the data would be accessed by PHP).
At this stage, I could for instance contribute that
"$user is an object that contains data about the current logged in user.
It has at least the following the properties:
Property Explanation Accessed as
uid the user id $user->uid
name the user name $user->name"
In this way, we would have a growing venue storing the relevant info, and you would not need to do all the work yourself. At a suitable time, someone could eventually take on the task of putting all the information together nicely and systematically.
As I continue with my own site over the next few weeks, I will most probably build up my own documentation of my findings in this regard, and could bit by bit feed this info into such a forum. I would not be surprised if there are other developers who have made their own annotations of these things and would be happy to post it to a venue of this sort.
Thomas
That is a great idea.
Who do we need to talk to about starting a forum?
Ben W
I think we can just start the forum
I think we can just start the forum. Do you feel like doing it...?
And then maybe announce it by making another (forum) post at http://drupal.org/node/add/forum, categorizing it under News and Announcements.
Incidentally, I noticed that the links at http://drupal.org/node/11819 (page.tpl.php etc.) point to pages that quite nicely list what appear to be global variables available to (at least) various PHPTemplate pages.
Also, at http://drupal.org/node/11812, in the replies entitled "header is missing" and "you might try" towards the end, there are some ideas of how to get environment variables listed.
On another note - as I don´t know much about the basic structure of Drupal - I´ve come to think that perhaps what variables are "global" at any point depends on what particular script or the particular point in the overall architecture one is working in, and perhaps also on what modules modules happen to be installed and enabled. If this is correct, the documentation would need to be structured accordingly.
Thomas
something i have found
something i have found extensivly helpful while templating and modifying blocks etc. is the following
<code><?php print_r(get_defined_vars()); ?>
placing the above in your node.tpl.php for example will show you all the available variables you have when you browse to a node page.