0

这个问题在其他人看来是一样的,但实际上是不同的。

情况是这样的:我有 2 个控制器,即 controller_1 和 controller_2。我有几个视图,但出于这种情况的目的,我将给出 view_1 和 view_2。

在调用controller_2 的索引时,它将在view_2 中呈现一个菜单。在这个菜单中,一个特定的链接应该在 view_2 中加载divview_1。

问题是,我已经在 controller_1 中创建了一个函数,它将使用模型所需的所有数据加载 view_1。当然,我可以在 controller_2 中再次加载模型,但问题是,我将重复在 controller_1 的一个函数中找到的代码。顺便说一句,controller_1 的行为就像一个 crud,而 controller_2 就像一个模块的控制器,它涉及几个 crud 的菜单。

那么我该怎么做呢?如何通过调用 controller_1 在 vi​​ew_2 中调用 view_1 以加载 view_1 并使用 controller_2 将其插入到 view_2 中?

编辑:如果您熟悉 Tiles of struts(旧版本),这就是我在这里尝试完成的类似事情。

4

2 回答 2

0

在 Code Igniter 中,当你需要在多个地方使用相同的逻辑时,通常你会创建一个helper或一个library

于 2012-06-29T12:56:35.057 回答
0

我想如果你只是从Controller_2的方法中使用重定向:

  Controller_2{
     function_to_call_a_method_from_controller_1{

        // You have to call the method of Controller 1
        return redirect('controller_1/function_of_controller_1_to_load_view');
     }


  }
于 2012-06-29T11:16:37.090 回答