作用:根據指定ID返回資料(網址)
代碼:
Parse error: parse error, unexpected T_VARIABLE in PHPDocument1 on line 6
//表 goods public function Goods($goods_id) { $sql = "SELECT g.goods_id,c.file_dir,c.parent_id,c.is_show AS c_is_show,g.is_show AS g_is_show ". " FROM ".self::$ecs->table('goods')." g ". " LEFT JOIN ".self::$ecs->table('category')." c ON g.cat_id=c.cat_id ". " WHERE g.goods_id='$goods_id' "; $rs = self::$db->getRow($sql); $arr = array(); if(!empty($rs)) { $arr['savepath'] = ($rs['g_is_show'] == 1 && $rs['c_is_show'] == 1) ? '/product/'.($rs['file_dir'] ? $rs['file_dir']:$rs['cat_id']).'/'.$rs['goods_id'].'.html' : ''; $arr['remoteurl'] = '/goods.php?id='.$rs['goods_id']; } return $arr; } //表 category public function Category($cat_id,$page = 1) { $sql = "SELECT c.cat_id,c.file_dir,c.parent_id,c.is_show ". " FROM ".self::$ecs->table('category')." c ". " WHERE c.cat_id='$cat_id' "; $rs = self::$db->getRow($sql); $arr = array(); if(!empty($rs)) { $arr['savepath'] = $rs['is_show'] == 1 ? '/product/'.($rs['file_dir'] ? $rs['file_dir']:$rs['cat_id']).'/index'.($page > 0 ? '-'.$page:'').'.html':''; $arr['remoteurl'] = '/category.php?id='.$rs['cat_id'].'&page='.$page; } return $arr; } //表article public function Article($article_id) { $sql = "SELECT a.article_id,c.cat_id,c.file_dir,c.is_open AS c_is_open ". " FROM ".self::$ecs->table('article')." a ". " LEFT JOIN ".self::$ecs->table('article_cat')." c ON a.cat_id=c.cat_id ". " WHERE a.article_id='$article_id' "; $rs = self::$db->getRow($sql); $arr = array(); if(!empty($rs)) { $arr['savepath'] = $rs['is_open'] == 1 ? '/article/'.($rs['file_dir'] ? $rs['file_dir']:$rs['cat_id']).'/'.$rs['article_id'].'.html' : ''; $arr['remoteurl'] = '/article.php?id='.$rs['article_id']; } return $arr; } //表 public function ArticleCat($cat_id,$page = 1) { $sql = "SELECT c.cat_id,c.file_dir,c.parent_id ". " FROM ".self::$ecs->table('article_cat')." c ". " WHERE c.cat_id='$cat_id' "; $rs = self::$db->getRow($sql); $arr = array(); if(!empty($rs)) { $arr['savepath'] = '/article/'.($rs['file_dir'] ? $rs['file_dir']:$rs['cat_id']).'/index'.($page > 0 ? '-'.$page:'').'.html'; $arr['remoteurl'] = '/article_cat.php?id='.$rs['cat_id'].'&page='.$page; } return $arr; }}
用法:
$arr = UrlPath::Goods(1024);print_arr($arr);
另外:開頭有一個報錯,不能這樣寫? procted $db = $GLOBALS['db'];
提問:
一:我想使用UrlPath::Goods($goods_id) 這樣的方式獲得指定的網址和靜態地址,
如何在“類” UrlPath 中不初始化這個類就可以使用公用的 $db 和 $ecs ?
二:我的這個寫法是不是有點問題?~ 另外那裡為什麼會報錯了?以前貌似可以這樣寫。?
回複討論(解決方案)
類變數不能使用變數的值來聲明,需要額外寫一個架構函數__construct來賦值
樓上說的對。