KesionCMS V6发布了一段时间了,使用过V6的朋友都知道科汛的系统函数标签已经是非常灵活了,更让人心动的是她的自定义样式输出(类似sql标签的循环体),但官方在考虑到整体性能的前提下,默认情况下只能用一些常见的字段
默认的可用字段如下:
但这些可用字段有可能不能完全满足所有用户的需求,比如一些用户想调用文章的作者,来源等,那就实现不了了
可以见这个用户的需求(http://bbs.kesion.com/dispbbs.asp?boardid=41&Id=104363&page=5)
没关系,如果有这个需求又不想用sql标签,只需要简单一步,就可以实现随意调用你想到的字段
V6开始的标签解释引擎已全面升级,扩展性极简单.科汛的系统函数标签解释文件主要在kesion.label.functioncls.asp这个文件中,那么请你用DW打开ks_cls/kesion.label.functioncls.asp
找到构造sql查询语句的通用函数,大约在200多行吧
'加载模型通用查询字段
Public Sub LoadField(ByVal ModelID,ByVal PrintType,ByVal PicStyle,ByVal ShowPicFlag,ByRef FieldStr,ByRef TableName,ByRef Param)
If ModelID="0" Then
TableName = "[KS_ItemInfo]"
FieldStr = "I.ChannelID,I.InfoID as ID,I.Title,I.Tid,I.Intro,I.PhotoUrl,I.AddDate,I.Inputer,I.Popular,I.Fname,I.Hits"
If PrintType=2 or (instr(LabelStyle,"{@photourl}")>0 and PrintType>2) Then Param = Param & " And I.PhotoUrl<>''"
Else
TableName=KS.C_S(ModelID,2)
Select Case KS.C_S(ModelID,6)
Case 1
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
FieldStr=FieldStr & ",I.TitleType,I.TitleFontColor,I.TitleFontType"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.Intro" : If PrintType=2 or (instr(LabelStyle,"{@photourl}")>0 and PrintType>2) Then Param = Param & " And I.PicNews=1"
If PrintType>=3 Then FieldStr=FieldStr & ",I.ReadPoint"
Case 2
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.PictureContent As Intro"
If PrintType>=3 Then FieldStr=FieldStr & ",I.ReadPoint"
Case 3
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.DownContent As Intro,I.DownSize,I.Rank"
If PrintType>=3 Then FieldStr=FieldStr & ",I.ReadPoint"
Case 4
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.FlashContent As Intro,I.Author,I.Rank"
If PrintType>=3 Then FieldStr=FieldStr & ",I.ReadPoint"
Case 5
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.ProIntro As Intro,I.BigPhoto,I.Price_market,I.Price_member,I.Price,I.Price_Original,I.Discount,I.Promodel,I.Point"
If KS.ChkClng(ParamNode.getAttribute("producttype"))<>0 Then Param =Param & " And I.ProductType="&KS.ChkClng(ParamNode.getAttribute("producttype"))
Case 7
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.MovieContent As Intro"
If PrintType>=3 Or PicStyle=13 Or PicStyle=14 Or PicStyle=15 Then FieldStr=FieldStr & ",I.MovieAct,I.MovieDY,I.MovieDQ,I.MovieTime,I.MovieYY,I.ReadPoint,I.Rank"
If PrintType=2 And PicStyle=15 Then FieldStr=FieldStr & ",I.MovieDy"
Case 8
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits,I.TypeID"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.GQContent As Intro"
If PrintType>=3 Or PicStyle=16 Or PicStyle=17 Then FieldStr=FieldStr & ",I.ValidDate,I.ContactMan,I.Tel,I.Address,I.Province,I.City,I.CompanyName"
If KS.ChkClng(ParamNode.getAttribute("typeid"))<>0 Then Param =Param & " And I.TypeID="&KS.ChkClng(ParamNode.getAttribute("typeid"))
Case Else
FieldStr = "I.ID,I.Title,I.Tid,I.PhotoUrl,I.AddDate,I.Inputer,I.Popular,I.Fname,I.Hits"
If PrintType=2 or (instr(LabelStyle,"{@photourl}")>0 and PrintType>2) Then Param = Param & " And I.PhotoUrl<>''"
End Select
If PrintType=4 Then FieldStr=FieldStr & GetDiyFieldStr(ModelID)
End If
End Sub
如果看懂代码的用户,相信很容易看出来是根据模型构造的查询字段,这里我们就以文章模型为例,找到如下代码
Case 1
FieldStr = "I.ID,I.Title,I.Tid,I.Inputer,I.Fname,I.AddDate,I.Popular,I.Hits,I.Author"
FieldStr=FieldStr & ",I.TitleType,I.TitleFontColor,I.TitleFontType"
If PrintType>=2 Then FieldStr=FieldStr & ",I.PhotoUrl,I.Intro" : If PrintType=2 or (instr(LabelStyle,"{@photourl}")>0 and PrintType>2) Then Param = Param & " And I.PicNews=1"
If PrintType>=3 Then FieldStr=FieldStr & ",I.ReadPoint"
其中红色的,i.author 是我加上的,就这么简单一步,你的系统函数标签的自定义样式里就已经直接用{@author}这样的标签调用出文章的作者了,其它模型类似,具体想要调用的字段可以打开ks_article表查看
疑问:
1.那这么简单,官方为什么不把所有字段都加进去呢?这样就不用用户自己加了,我方便?
答:我上面已经说到了考虑到性能问题,查询字段应该尽量的少.所以也不是说你查询越多越好.
2.为什么我按上面修改了,但我用{@字段名称}还是查询不出来呢?
答:检查标签属性里的范围有没有指定具体的模型,只有指定具体模型才有效,否则她查询的是KS_ItemInfo表