写有
//。。?????的地方下的那行代码,帮我解释下吧,麻烦了啊(顺便帮我看下我写的有没有错啊)function tree () 
{
global $mainframe;

//now check if there is start word
$init = JRequest::getVar('init','','get');//从地址栏取得参数
$init = substr($init,0,1);
//print_r("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//print_r($init); //如果地址栏中没有init参数,那么默认为a
if(!$init){
$this->setRedirect('index.php?option=com_singletable&task=region.tree&init=a');
return;
}

$db = & JFactory::getDBO();
$view = &$this->getView( 'region','html');

$regions = $this->getRegions($init);//调用下面的getRegions方法,返回menu
$regions = $this->treeMenu($regions);
$view->assignRef('regions',$regions);//定义项名为regions,值为$regions

$view->display();
}


function getRegions($init='a')
{
$menus = $mapping = array();//创建数组????这个对吗
$db = &JFactory::getDBO();

$sql = "SELECT r.* FROM #__regions AS r " .
" LEFT JOIN #__regions AS rr ON(r.parent_region_id = rr.id) ".
" WHERE (r.parent_region_id=0) ".
" OR (rr.name LIKE ".$db->Quote($db->getEscaped($init.'%',false),false).")".
" ORDER BY r.layer_id ASC ,r.name ASC ";
$db->setQuery($sql);
$result = $db->loadObjectList();//取得sql下的集合
//遍历集合对象
foreach($result as $item)
{
/**
*如果parent_region_id 不存在并且被遍历出来的对象的name的第一个字母与所传过来的参数init不等,
*那么进入下一层循环,直到相等为止
*/
//check if is A start
if(!$item->parent_region_id && strtoupper(substr($item->name,0,1))!=strtoupper($init)){
continue;
}
//如果以上条件相等,那么定义一个对象$item_array,把item的值传给它;
$item_array = array(
'id' =>$item->id,
'parent_region_id' =>$item->parent_region_id,
'name' =>$item->name,
'tag' =>$item->tag,
'GEO_ID' =>$item->GEO_ID,
'layer_id' =>$item->layer_id,
'children' =>array()
);

//if permission_id is sh-04,parent_permission_id is sh-02
//。。?????
if(isset($mapping[$item->parent_region_id])){

//。。?????
$temp = $mapping[$item->parent_region_id];
//。。?????
$new_temp = $temp.'*'.$item->id;
$mapping[$item->id] = $new_temp;

//if temp is sh-01*sh-02
$temp = explode('*',$temp);

//print_r($temp);



for($i=0;$i<count($temp);$i++){

if(!isset($temp_menu)){ //。。?????
$temp_menu = &$menus[$temp[$i]]['children'];
}else{
$temp_menu = &$temp_menu[$temp[$i]]['children'];
}
} //。。?????
$temp_menu[$item->id] = $item_array;

}else{
//permission_id is sh-01
$mapping[$item->id] = $item->id;

$menus[$item->id] = $item_array;
}
unset($temp_menu);

}

return $menus;
}

function treeMenu($menus,$layer_id = 1,$html = '')
{
global $html;
$children_layer = $layer_id + 1;
foreach ($menus as $menu)
{ $submenu = count($menu['children']) > 0 ?true:false;
if(!$submenu){
$icon = ';icon:_doc';
}else{
$icon = '';
}
$html .= '<li><a><!-- id:'.$menu['id'].$icon.' -->'.$menu['name'].'</a>';
if($submenu){
$html .= '<ul>';
$this->treeMenu($menu['children'], $children_layer,$html);
$html .= '</ul></li>';
}else{
$html .= '</li>';
}
}
return $html;

}另外还有2个问题:
1.$db=& JFactory::getDBO();//如果建了多个数据库,如何得知取到的是当前数据库
2.$user=&JFactory::getUser();//如何得知取的一定是user表中的用户信息(取得的数据只有一条吗?)

解决方案 »

  1.   

    兄弟,你一下发这么一大堆代码来没有人看的,还有后面你问的那两个问题,JFactory类都没有给,鬼知道里面写的一些什么东西啊?问问题要抓重点,需要提供的代码要以简单的形式表现出来
      

  2.   

    太长了,看得眼花,就是判断xxx
      

  3.   

    isset就是判断变量是否定义过
    太长了  还没排版  花眼
      

  4.   

    去JFactory类里面查getDBO和getUser