我正在尝试创建一个从选择框中保存值的块。但是,重新加载后, variable_get 不会返回保存的值......所以 variable_set 接缝不起作用。
我在这里做错了什么?(Drupal 6)
function get_courses(){
global $user;
$my_items_sql = 'SELECT course_node.uid, ';
//get the course nid
$my_items_sql .='course_node.nid as course_nid, ';
//get the course title
$my_items_sql .='course_node.title as course_title ';
$my_items_sql .=' from node as course_node where course_node.type="course" and course_node.uid = "'.$user->uid.'"';
$my_items_sql .=' order by course_node.nid; ';
$my_items_data= db_query($my_items_sql);
$my_courses = array();
while ($row = db_fetch_array($my_items_data)) {
//$course_node = node_load($row["course_nid"]);
$my_courses[$row["course_nid"]]=$row["course_title"];
}
//$variables['courses']=$my_courses;
//drupal_add_js(array('courses'=>$my_courses), "setting");
return $my_courses;
}
function front_page_block($op='list',$delta = 0, $edit = array()) {
$course_options = array();
$courses = get_courses();
$tmp = $courses;
$first_course = $tmp;
reset($first_course );
$first_course_nid = key($first_course);
$first_course_nid = key($first_course);
switch($op){
case 'list':
$blocks[0]['info']= t('Course Data Loader');
$blocks[0]['cache']= BLOCK_NO_CACHE;
return $blocks;
case 'configure':
$form['course_to_display'] = array(
'#type' => 'select',
'#description' => t('Display flashcards from which deck on the front page?'),
'#options' => $courses,
'#default_value'=>variable_get('front_page_deck_to_load', $first_course_nid)
);
return $form;
case 'save':
variable_set('front_page_deck_to_load',
$edit['front_page_deck_to_load']);
break;
}