Global variable in Drupal module

Ở trang php bình thường, khi muốn lấy giá trị của biến để sử dụng trong hàm chỉ đơn giản là global biến đó lên:

1
2
3
4
5
6
$_User = “user”;
function test()
{
       global $_User;
       ...
}

Nhưng trong Drupal làm vậy lại không được. Muốn sử dụng được thì phải khai báo 1 biến là global trước, sau đó mớ i gán giá trị và truy xuất được:

1
2
3
4
5
6
7
global $_User;
$_User = “user”;
 
function test() {
  global $_User;
  ..
}

Chẳng biết tại sao nữa :(

[Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
This entry was posted in Drupal. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

CAPTCHA image
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>