开发者

how to get drupal var from the module in the external php?

I don't know how to get access to the drupal variable in the external .php file. In the module i assign the variable in order to use it in the template:

$variables['teams'] = $output; 

In the template file i can access it by:

<?php foreach ($teams as $row) { ?>
<?php print $row['team_name']?>
<?php } ?> 

But I'd like to access this variable from 开发者_如何学JAVAanother external php file. How can i do it?


You should give us some more information about where you are planning on using that variable. If you are planning on using the variable in a template file, $variables should be fine, otherwise you could store it somewhere or set is as a global. If you want to use it from another module, you should make sure that the hook that sets the variable has run before the hook where you plan on using the variable. If they are the same hook (i.e. nodeapi) make sure the weight of the second module is higher. If you need to use the variable outside the Drupal bootstrap, store it. You can use the drupal_cache_set or variable_set.


You have to include script, which generates that variable.

Or, find in code, where that variable was generated.
For example, if
$output = SomeClass::SomeMethod();
you can move this code to your script.

Read more about scopes of variables in manual.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜