其实可以直接在vm中使用的系统变量都是在NVelocityViewEngine类的CreateContext方法中定义的。下面我们就看看到底定义了哪些(详见代码中的注释说明):
1
private IContext CreateContext(IRailsEngineContext context, Controller controller)
2
innerContext.Add(TemplateKeys.Controller, controller);
//当前请求的上下文,请求,Session等可以直接使用
6
innerContext.Add(TemplateKeys.Context, context);
7
innerContext.Add(TemplateKeys.Request, context.Request);
8
innerContext.Add(TemplateKeys.Response, context.Response);
9
innerContext.Add(TemplateKeys.Session, context.Session);
10
//对应的controller中的Resources中所有资源可以直接在vm中使用
11
if (controller.Resources != null)
12![]()
//所有Params中的值可以直接在vm中使用
19
foreach(String key in context.Params.AllKeys)
20![]()
//常见的系统类可以之间使用,比如可以直接在vm中使用$Int32.MaxValue
49
foreach(object helper in builtInHelpers)
50![]()
//定义的Helper类可以直接在vm中使用
54
if (controller.Helpers != null)
55
}
2
//当前请求的上下文,请求,Session等可以直接使用
6
7
8
9
10
//对应的controller中的Resources中所有资源可以直接在vm中使用
11
12
//所有Params中的值可以直接在vm中使用
19
20
//常见的系统类可以之间使用,比如可以直接在vm中使用$Int32.MaxValue
49
50
//定义的Helper类可以直接在vm中使用
54
55