首页 > 解决方案 > 在 IHP 的 Helper 文件中正确导入

问题描述

我正在尝试将我的一些视图和控制器逻辑集中到它们各自的帮助文件中的帮助程序Application.Helper.ControllerApplication.Helper.View.

我发现我无权访问我可以访问的包,例如在我的控制器文件中。例如Data.Text和许多其他人一样。当我什至无法访问管道操作员时,我停止尝试将它们全部导入。

View.hs帮助文件相同,无法访问hsx语法。

有没有简单的方法来解决这个问题?你如何解决这个问题?必须在此处手动进行导入吗?

对我来说,在文件夹中制作 Helper 文件似乎更简单,Web/Controller因为该文件夹中的模块似乎可以毫无问题地进行正确的自动导入。

我的 Controller.hs 文件现在看起来,不支持 Data.Text 和管道运算符之类的东西:

module Application.Helper.Controller (
    module IHP.LoginSupport.Helper.Controller
) where

-- Here you can add functions which are available in all your controllers

import IHP.LoginSupport.Helper.Controller
import Generated.Types


type instance CurrentUserRecord = User

和不支持 hsx 语法的 View.hs:

module Application.Helper.View (
    -- To use the built in login:
    module IHP.LoginSupport.Helper.View
) where

-- Here you can add functions which are available in all your views

-- To use the built in login:
import IHP.LoginSupport.Helper.View

标签: haskellihp

解决方案


Application.Helper.Controller你需要 import IHP.ControllerPrelude,像这样:

module Application.Helper.Controller (
    module IHP.LoginSupport.Helper.Controller
) where

-- Here you can add functions which are available in all your controllers

import IHP.LoginSupport.Helper.Controller
import Generated.Types
import IHP.ControllerPrelude


type instance CurrentUserRecord = User

Application.Helper.View你需要 import IHP.ViewPrelude,像这样:

module Application.Helper.View (
    -- To use the built in login:
    module IHP.LoginSupport.Helper.View
) where

-- Here you can add functions which are available in all your views

-- To use the built in login:
import IHP.LoginSupport.Helper.View
import IHP.ViewPrelude

这应该适当地添加到国际水文计划项目模板中。


推荐阅读