Drupal: How to define variables in one module functions and call it from another in Drupal 7
I writing a module for Drupal 7. It must get current $node
variable in one function, e.g. hook_init()
or similar, and this variable should be accessible from another function. I found discussion about node_load(arg(1))
and the author of solution said that performance is no concern because of caching.
So, should I call node_load()
in every function I need not being afraid of performance issues of are there any other ways to pass variables between module functions?
To be more exact: I've placed a block with module on pages with a certain node types and in hook_block_view function I need to access to current node object. I'm succeeded using node_load so far. But maybe there is a better way.
Thanks in advance!
In drupal 7 node_load()
calls entity_load()
, which caches the results, so if you call node_load()
twice, it will be returned from cache.
Using node_load()
is better solution than passing global variables between modules, especially if you use some third-party caching modules (APC, memcached or other). If you care about performance just try to use one of these modules (I prefer memcached).
精彩评论