2015-07-12 70 views
0

我看了虽然yesod教程和源代码,但没有办法做这样的事情......我必须使用模式匹配吗?如何从approot(网址)获取字符串?

https://hackage.haskell.org/package/yesod-core-1.2.2/docs/Yesod-Core.html

来源:

 
-- | How to determine the root of the application for constructing URLs. 
-- 
-- Note that future versions of Yesod may add new constructors without bumping 
-- the major version number. As a result, you should /not/ pattern match on 
-- @[email protected] values. 
data Approot master = ApprootRelative --^No application root. 
        | ApprootStatic !Text 
        | ApprootMaster !(master -> Text) 
        | ApprootRequest !(master -> W.Request -> Text) 

回答

1

您是否在寻找从Yesod.Core.HandlergetUrlRenderYesod.Core也许renderRoute

+0

renderRoute只能从(路由a)获得相对的url字符串,但是我想获得完整的绝对路由..这很容易通过@ {}符号嵌入到hamlet中... – doofin

+0

@doofin这是我用过的(对不起,如果它不适合你的用例):https://git.gnu.io/snowdrift/snowdrift/blob/master/tests/TestImport.hs#L548 https://git.gnu.io/snowdrift/snowdrift /blob/master/Handler/User.hs#L87两者都提供绝对网址。 –

+0

我看到:render :: RenderRoute App => Text - > Route App - > Text render appRoot =((appRoot <>“/”)<>)。 T.intercalate“/”。 fst。 renderRoute,但yesod typeclass中定义的approot函数的类型不是text ..所以你给渲染函数作为第一个参数是什么?我们可以定义一个批准字符串,但是这应该已经通过yesod – doofin