php 为什么基本超级全局失败?
我正在使用全局变量在这样的函数之间共享变量
<?php
$whatyear;
$whatfirstname;
$whatlastname;
function mycustom_user_register_submit($form, &$form_state)
{
$GLOBALS["whatyear"]=$form_state['values']['yearofstudy'];
$GLOBALS["whatfirstname"]=$form_state['values']['firstname'];
$GLOBALS["whatlastname"]=$form_state['values']['lastname'];
}
function course_registration_user_insert(&$edit, $account, $category)
{
$newuserid=$account->uid;
$yearofstudy=$GLOBALS["whatyear"];
$fname=$GLOBALS["whatfirstname"];
$lname=$GLOBALS["whatlastname"];
//now use vars
drupal_set_message('dear '.$fname.' '.$lname.' ,'.'account uid is '.$account->uid);
}
但是变量
fname,lname,学习年份
空得惊人!请帮我找出原因。 我收到类似错误
Notice: Undefined index: whatyear in course_registration_user_insert() (line 110 of C:\wamp\www\drupal-7.1\sites\all\modules\course_registration\course_registration.module).
i am using globals to share variables between functions like this
<?php
$whatyear;
$whatfirstname;
$whatlastname;
function mycustom_user_register_submit($form, &$form_state)
{
$GLOBALS["whatyear"]=$form_state['values']['yearofstudy'];
$GLOBALS["whatfirstname"]=$form_state['values']['firstname'];
$GLOBALS["whatlastname"]=$form_state['values']['lastname'];
}
function course_registration_user_insert(&$edit, $account, $category)
{
$newuserid=$account->uid;
$yearofstudy=$GLOBALS["whatyear"];
$fname=$GLOBALS["whatfirstname"];
$lname=$GLOBALS["whatlastname"];
//now use vars
drupal_set_message('dear '.$fname.' '.$lname.' ,'.'account uid is '.$account->uid);
}
But the variables
fname,lname,yearofstudy
are shockingly empty! please help me figure out why.
am getting errors like
Notice: Undefined index: whatyear in course_registration_user_insert() (line 110 of C:\wamp\www\drupal-7.1\sites\all\modules\course_registration\course_registration.module).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用这样的全局变量:
如果这不起作用,请确保在同一个 php 实例中以正确的顺序调用这些函数。如果在一个页面上调用第一个,然后在另一个页面上调用insert,则会打开一个新的php副本,并且您将丢失环境变量。
Try using global variables like this:
If this doesn't work, make sure these functions are called in the same php instance in the right order. If the first one is called on one page, and then insert is called on another page, a new copy of php will be opened, and you will lose your environment variables.