表达式引擎控制器

发布于 2024-11-18 14:58:59 字数 94 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画尸师 2024-11-25 14:58:59

控制器是应用程序的核心,因为它们决定如何处理 HTTP 请求。

您可能很清楚, CodeIgniter Controller 只是一个类文件,以可以与 URI 关联的方式命名。

<?php
    class Blog extends CI_Controller {

        public function index() {
            echo 'Hello World!';
        }
    }
?>

ExpressionEngine 的等效项是模板组和模板,并在控制面板的模板中进行管理经理。

在此处输入图像描述

由于 EE 的模板组和模板可以任意命名,因此 URL 结构 毫不奇怪地松散地模仿了 CodeIgniter 应用程序 — 毕竟,EE 构建的关于 CI。

例如,考虑以下 URI:example.com/index.php/blog

  • CodeIgniter 将尝试查找名为 blog.php控制器并加载它。
  • ExpressionEngine 将尝试查找名为 blog模板组并加载名为 index模板

继续这个示例,URI 的第二段确定调用控制器中的哪个函数(对于 CodeIgniter)或加载哪个模板(对于 ExpressionEngine)。

构建相同的 URI:example.com/index.php/blog/entry

  • CodeIgniter 会尝试查找名为 blog.php 的控制器并加载它。
  • ExpressionEngine 将尝试查找名为 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.

<?php
    class Blog extends CI_Controller {

        public function index() {
            echo 'Hello World!';
        }
    }
?>

The ExpressionEngine equivalent are template groups and templates, and are managed from within the Control Panel's Template Manager.

enter image description here

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

  • CodeIgniter would attempt to find a controller named blog.php and load it.
  • ExpressionEngine would attempt to find the template group named blog and load the template named index.

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

  • CodeIgniter would attempt to find a controller named blog.php and load it.
  • ExpressionEngine would attempt to find the template group named blog and load the template named entry.

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.

好久不见√ 2024-11-25 14:58:59

我知道这已经很旧了,但我只是认为看到这个的人可能会发现实际的回复很有用。
正如其他人所说,在 ExpressionEngine 中默认情况下会忽略控制器的路由。
要更改此设置,您必须编辑第一个 index.php 并注释掉默认路由:

// $routing[‘directory’] = ‘’;
// $routing[‘controller’] = ‘ee’;
// $routing[‘function’] = ‘index’;

完成后,您可以添加控制器,就像 @rjb 在他的回复中写的那样。

<?php
class Blog extends CI_Controller {

    public function index() {
        echo 'Hello World!';
    }
}
?>

完成此操作后,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:

// $routing[‘directory’] = ‘’;
// $routing[‘controller’] = ‘ee’;
// $routing[‘function’] = ‘index’;

Once that is done, you can add controllers just like @rjb wrote on his response.

<?php
class Blog extends CI_Controller {

    public function index() {
        echo 'Hello World!';
    }
}
?>

After this is done, ExpressionEngine will check first for controllers and if none is found, it will look for templates.

我的鱼塘能养鲲 2024-11-25 14:58:59

一般来说,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文