表达式引擎控制器
我在 Expression Engine 中构建我的第一个站点,我想知道如何在 EE 中使用自定义控制器,就像在 Codeigniter 中一样,或者 EE 的等效项是什么?
Im building my first site in Expression Engine, I was wondering how to use custom controllers in EE, like I would in Codeigniter, or what is the EE equivalent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
控制器是应用程序的核心,因为它们决定如何处理 HTTP 请求。
您可能很清楚, CodeIgniter Controller 只是一个类文件,以可以与 URI 关联的方式命名。
ExpressionEngine 的等效项是模板组和模板,并在控制面板的模板中进行管理经理。
由于 EE 的模板组和模板可以任意命名,因此 URL 结构 毫不奇怪地松散地模仿了 CodeIgniter 应用程序 — 毕竟,EE 是构建的关于 CI。
例如,考虑以下 URI:
example.com/index.php/blog
blog.php
的控制器并加载它。blog
的模板组并加载名为index
的模板。继续这个示例,URI 的第二段确定调用控制器中的哪个函数(对于 CodeIgniter)或加载哪个模板(对于 ExpressionEngine)。
构建相同的 URI:
example.com/index.php/blog/entry
blog.php
的控制器并加载它。blog
的模板组并加载名为entry
的模板。从第三个及之后的 URL 段开始,CodeIgniter 和 ExpressionEngine 开始采取不同的方法。 (对它们差异的完整解释超出了本答案的范围)。
虽然 CodeIgniter 和 ExpressionEngine 之间有许多相似之处,但在非常低的级别上,CodeIgniter 可以让您构建 Web 应用程序,而 ExpressionEngine 可让您构建网站。
Controllers are the heart of your application, as they determine how HTTP requests should be handled.
As you're probably well-aware, a CodeIgniter Controller is simply a class file that is named in a way that can be associated with a URI.
The ExpressionEngine equivalent are template groups and templates, and are managed from within the Control Panel's Template Manager.
Since EE's template groups and templates can be named anything you want, the URL structure unsurprisingly loosely mimics a CodeIgniter app — after all, EE is built on CI.
For example, consider this URI:
example.com/index.php/blog
blog.php
and load it.blog
and load the template namedindex
.Continuing with this example, the second segment of the URI determines which function in the controller gets called (for CodeIgniter) or which template gets loaded (for ExpressionEngine).
Building off the same URI:
example.com/index.php/blog/entry
blog.php
and load it.blog
and load the template namedentry
.Starting with the third and beyond URL segments is where CodeIgniter and ExpressionEngine start to take different approaches. (A full explanation of their differences is beyond the scope of this answer).
While there are many similarities between CodeIgniter and ExpressionEngine, at a very low-level, CodeIgniter lets you build Web Apps while ExpressionEngine lets you build Web Sites.
我知道这已经很旧了,但我只是认为看到这个的人可能会发现实际的回复很有用。
正如其他人所说,在 ExpressionEngine 中默认情况下会忽略控制器的路由。
要更改此设置,您必须编辑第一个 index.php 并注释掉默认路由:
完成后,您可以添加控制器,就像 @rjb 在他的回复中写的那样。
完成此操作后,ExpressionEngine 将首先检查控制器,如果没有找到,它将查找模板。
I know this is old, but I just thought someone looking at this might find the actual response useful.
As others have said, routes for controllers are ignored by default in ExpressionEngine.
To change this, you have to edit the first index.php and comment out the routing defaults:
Once that is done, you can add controllers just like @rjb wrote on his response.
After this is done, ExpressionEngine will check first for controllers and if none is found, it will look for templates.
一般来说,ExpressionEngine使用模板组和模板来渲染内容。
EE构建于 CI 之上,但它的功能与 CI 不同,因为它是一个 CMS,而不是一个应用程序框架。
Generally-speaking, ExpressionEngine uses template groups and templates to render content.
EE is built on CI, but it doesn't function like CI, as it's a CMS, not an application framework.