機能: 指定されたIDに従ってデータ(URL)を返す
コード:
<?phpclass UrlPath{ protected $db = $GLOBALS['db']; //报错 protected $ecs = $GLOBALS['ecs']; //报错 <b>Parse error</b>: parse error, unexpected T_VARIABLE in <b>PHPDocument1</b> on line <b>6</b><br /> //表 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);
変数の値を使用してクラス変数を宣言することはできません、値を割り当てるために追加のアーキテクチャ関数 __construct を記述する必要があります
上の人は正しいです。 。