1

我正在使用 Codeigniter:我有两个控制器。他们使用不同的模型。他们没有任何共同之处。控制器 1 是一个登录控制器,如果我的登录凭据正确,它会将我引导至安全页面。我只是想要 Controller 2: 只加载这个页面的中间部分,就是这样。为什么用 CI 做这件事这么难?

+-------------------------------------------------------+
|View "Home_Page"                                       |
+--------------------------------------------------------
| TOP:                                                  |
|Controller 1: function checklogin(){} loads this part  |
|                                                       |
--------------------------------------------------------+
|Middle:                                                |                                  
|Controller 2: function content(){ } loads this part    |
|                                                       |
--------------------------------------------------------+
|Bottom:                                                |                                  
|Controller 1: function checklogin(){} loads this part  |
|                                                       |
--------------------------------------------------------+
4

3 回答 3

2

回答你的问题。

因为CI不是开发来做这种事情的?

不是 MVC 的东西?控制器不调用控制器,模型不调用控制器,视图不调用控制器,控制器调用它们想要的任何东西,只有调用控制器的东西是路由。

如果您想要类似的功能,请阅读有关HMVC / Modular 分离的信息。

无论如何,这是不好的做法,请考虑将您的代码重组为 MVC 并停止尝试让 CodeIgniter 做它不应该做的事情。

关于 MVC 的内容以及模型的用途。

控制器 1

public function index() {
    $this->load->view("header");
    $this->load->view("top");
    $this->load->view("middle");
    $this->load->view("bottom");
}

控制器 2

public function index() {
    $this->load->view("header");
    $this->load->view("middle");
}
于 2012-08-27T04:37:11.147 回答
0

There are several auth libraries that work just fine, and they don't operate this way.

Generally the flow in CI is:

Request -> Front Controller 
-> Route
-> Controller
[-> Auth Library 
    [-> Auth Model]
] 
-> Display View

Brackets are there to indicate optional components.

The controller will run the auth code, be it a library or another method in your controller, and then display a view or redirect the user based upon the outcome.

I personally use Tank Auth, but there are many others that will work as authentication libraries.

于 2012-08-28T00:25:11.317 回答
0

我认为您需要母版页,

参考这个

于 2012-08-27T04:50:39.573 回答