表达式引擎 2 中 CodeIgniter 风格的基于规则的 URL 路由?

发布于 2024-12-08 20:02:14 字数 289 浏览 0 评论 0 原文

我是 EE 开发的新手,但我在 CI 方面拥有相当丰富的经验。

我想设置一个像这样的 URL 结构:

/channel-name/*
/channel-name/*/videos
/channel-name/*/shows
/channel-name/*/awards

我现在能想到的唯一方法是在模板中使用条件。有没有一种类似于 CodeIgniter 允许我这样做的方法来路由 URL?

再次,如果我遗漏了一些明显的东西,请原谅我的无知!

谢谢。

So I’m new to EE development, but I’ve got a fairly extensive experience with CI.

I’d like to set up a URL structure like this:

/channel-name/*
/channel-name/*/videos
/channel-name/*/shows
/channel-name/*/awards

The only way I can think to do it now is by using a conditional in the template. Is there a way to route the URL similar to how CodeIgniter would allow me to do it?

Again, please forgive my ignorance if I’m missing something glaringly obvious!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

锦欢 2024-12-15 20:02:14

EE 没有您可能在 CI、Rails 等中使用的炫酷路由。相反,EE 是为了处理模板中的大部分逻辑而构建的——这对新手来说是福音,但对更有经验的开发人员来说可能是一种烦恼。在模板中,您通常会使用基于 URL 段的条件来实现路由目标。

就你而言,我可能会大量使用嵌入标签。嵌入是在 EE 中完成许多事情的好方法,因为它们可以帮助您绕过 EE 中嵌套循环的一些奇怪的解析顺序问题。示例:

{exp:channel:entries channel="my_channel_name" url_title="{segment_2}" limit="1"}

  {if segment_3 == "awards"}
    {embed="channel/awards" entry_id="{entry_id}"
  {if:elseif segment_3 == "shows"}
    ...
  {if:else}
    {embed="/channel/basic_entry" entry_id="{entry_id}"}
  {/if}

{exp:channel:entries}

像 Switchee 这样的东西可以使这样的控制语句更好一些。 http://www.google.ca /search?gcx=c&sourceid=chrome&ie=UTF-8&q=switchee

您还可以使用免费赠品 http://devot-ee.com/add-ons/freebie (完全公开,我做了这个)告诉 EE 不要解析 URL 的某些部分,这给了你一点更自由地使用它。

EE doesn't have the cool routing you might be used to in CI, Rails, etc. Instead, EE is built to handle most of the logic from a template — which is a boon to newcomers and possibly an annoyance to more experienced devs. In templates, you'll generally use conditionals based on the URL segments to accomplish your routing goals.

In your case, I would probably use embed tags pretty heavily. Embeds are a good way to get a lot of things done in EE, because they help you bypass some of the quirky parse order issues EE has with nested loops. Example:

{exp:channel:entries channel="my_channel_name" url_title="{segment_2}" limit="1"}

  {if segment_3 == "awards"}
    {embed="channel/awards" entry_id="{entry_id}"
  {if:elseif segment_3 == "shows"}
    ...
  {if:else}
    {embed="/channel/basic_entry" entry_id="{entry_id}"}
  {/if}

{exp:channel:entries}

Something like Switchee can make control statements like this a little better. http://www.google.ca/search?gcx=c&sourceid=chrome&ie=UTF-8&q=switchee

You can also use Freebie http://devot-ee.com/add-ons/freebie (full disclosure, I made this) to tell EE not to parse some parts of the URL, which gives you a little more freedom to play around with it.

她如夕阳 2024-12-15 20:02:14

这是 EE 中路线的很好的解释。由于 EE 现在是 CI2,因此路由的工作方式非常接近相同:

http://venodesigns.net/2011/05/07/when-expressionengine-defaults-are-not-enough/

Here's a nice explanation of routes in EE. since EE is now CI2, then routing works pretty close to the same way:

http://venodesigns.net/2011/05/07/when-expressionengine-defaults-are-not-enough/

童话里做英雄 2024-12-15 20:02:14

使用类别将是 ExpressionEngine 中最符合您需求的逻辑分类法,并为您提供所需的 URL 结构。

默认情况下,ExpressionEngine URL 类别段如下所示:

/index.php/template_group/template_name/CategoryID

使用您的示例,您将创建一个

  • 视频
  • 节目
  • 奖项

许多开发者将其模板组命名为与频道名称相匹配,这使得 理解 ExpressionEngine URL 逻辑。

开箱即用后,您的 URL 段将如下所示:

/index.php/channel-name/template-name/C1

我建议设置 Category URL 指示器,因此您可以在 URL 中为类别使用标识符(例如 category),而不是无语义的类别 ID。

类别 URL 将类似于:

/index.php/channel-name/category/videos

更进一步,通过 从中删除 index.php ExpressionEngine URL,您可以实现:

/channel-name/category/videos

正如您在 ExpressionEngine 中发现的那样,URL 和模板的灵活性允许采用多种方式组织和显示数据。

例如,您可以使用标签而不是类别对数据进行分组,但您需要使用第三方加载项,因为标记不包含在内ExpressionEngine 的核心功能。

Solspace 标签模块,DevDemon 的Tagger 和 Jamie Rumbelow 的 Taggable 都是三个合适的候选者。

Using categories would be the most logical taxonomy in ExpressionEngine for your needs and provide you with the desired URL structure.

By default, the ExpressionEngine URL category segments look like this:

/index.php/template_group/template_name/CategoryID

Using your example, you'd create a Category Group with the following Categories:

  • Videos
  • Shows
  • Awards

Many Developers name their template groups to match the channel name, which makes understanding ExpressionEngine URLs logical.

Out of the box, your URL segments would look like this:

/index.php/channel-name/template-name/C1

I would recommend setting a Category URL Indicator, so you can use an identifier (e.g. category) in your URLs for your categories instead of the unsemantic Category IDs.

The category URLS would then be something like:

/index.php/channel-name/category/videos

Taking this a step further, by removing index.php from ExpressionEngine URLs, you could achieve:

/channel-name/category/videos

As you'll find out in ExpressionEngine, the flexibility of the URLs and templates allows for many ways of organizing and displaying your data.

For example, you could use Tags instead of Categories for grouping your data, but you'd need to use a third-party Add-On, since tagging is not included as a core feature of ExpressionEngine.

The Solspace Tag Module, DevDemon's Tagger and Jamie Rumbelow's Taggable are all three suitable candidates.

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