我应该将要在 CakePHP 应用程序中抽象的文本放置在哪里?

发布于 2024-09-13 13:33:51 字数 158 浏览 6 评论 0原文

我正在编写一个 CakePHP 应用程序,并尝试将经常显示(或特别长)的文本保存在配置文件中,以便我们可以轻松编辑它。
我应该将该文件放在哪里以及如何访问它?
我还担心当我们需要显示文本时读取该文件的速度以及锁定其他进程能够使用它时的权衡。这是我应该担心的事情还是框架可以处理这个问题?

I am writing a CakePHP application and am trying to have text that is frequently displayed (or particularly long) saved in a config file somewhere that we can easily edit it.
Where should i put this file and how do I access it?
I am also worried about the tradeoff in speed of reading this file when we need to display text, as well as locking from other processes being able to use it. Is this something I should worry about or does the framework handle that?

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

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

发布评论

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

评论(3

毁我热情 2024-09-20 13:33:51

是的,Rob说得很好。你可以把它放在视图中,无论是静态的还是动态的。如果是静态的,你可以直接将HTML部分放在一个元素中,然后可以在任何你想要的地方调用它。如果是静态的,你可以直接将HTML部分放在一个元素中,然后可以在任何你想要的地方调用它。动态的,您可以通过模型从数据库中获取数据,将其传递给控制器​​,然后可以将其渲染到元素(视图的一小部分,或者您可以将其称为抽象)。

Yes,Rob stated it quite good.You can put it in view,either if it's Static or Dynamic.If it's static,you can directly put the HTML part in a element and then can call it whatever place you want to.And if it's dynamic,you can fetch the data from the database through Model,pass it on to Controller and can then render it to a element(small part of View or you can call it Abstract).

染火枫林 2024-09-20 13:33:51

如果它显示在多个位置,但是静态的,则一个元素就足够了。我不确定我是否会太担心长度,但元素也可以在那里工作。如果需要频繁编辑,那么您可能需要考虑放入 CakePHP 可以轻松处理的数据库,尽管有人可能已经创建了一个同样可以工作的平面文件数据源(我从未看过)。

如果您计划拥有大量非结构化文本,您可能还想考虑使用 MongoDB、CouchDB 或其他“NoSQL”变体。对于你提到的内容来说,这似乎不值得,但如果你有更大的背景......也许。

该框架不会处理速度权衡——事实上,使用框架根本就是您已经选择支持的权衡。我也不会太担心锁定,除非您预期高负载和频繁编辑,但这只是本能反应。请持保留态度,因为我不知道你的具体情况。

If it's displayed on multiple locations, but static, an element will suffice. I'm not sure I'd worry much about length, but an element would work there too. If frequent edits are required, then you may want to think about putting in the database where CakePHP can handle it easily, although someone may have created a flat file datasource (I've never looked) that would work just as well.

You may also want to look into using MongoDB, CouchDB or another "NoSQL" variant if you plan to have any significant amount of unstructured text. It doesn't seem worth it for what you've mentioned, but if you have a larger context...maybe.

The framework won't handle the speed tradeoff--in fact, using a framework at all is a trade-off that you've already opted in favor of. I also wouldn't worry too much about locking unless you anticipate high load and frequent edits, but that's just a visceral response. Take it with a grain of salt since I don't know your particulars.

笔落惊风雨 2024-09-20 13:33:51

...有经常显示的文本
(或者特别长)

根据手册,最好的做法是在视图元素中存储跨多个视图使用的文本(正如 Rob Wilkerson 所指出的)。

在我们可以的地方
轻松编辑它。

即使在这种情况下,视图元素仍然是选择,因为您可以从多个视图引用这个单个元素,所以不需要存储在数据库中。如果您更改视图元素,则无论在何处引用/嵌入它,它的更改都会立即生效(非常合乎逻辑)。

...保存在配置文件中

这将被认为是不好的做法,因为您开始削弱 MVC 结构。

超级简单、超级简短的阅读:
http://book.cakephp.org/view/1081/Elements

祝你好运你的项目。

...have text that is frequently displayed
(or particularly long)

According to the manual, it is good practice to store text that is used across multiple views in a view element (as pointed out by Rob Wilkerson).

somewhere that we can
easily edit it.

Even in this case a view element is still the choice, as you can refer to this single element from multiple views, so no need for storing in a db yet. If you change the view element, it changes become immediatly effective, wherever it is referenced/embedded (quite logical).

... saved in a config file

This would be considered bad practice, as you start weakening your MVC structure.

Supereasy, supershort reading:
http://book.cakephp.org/view/1081/Elements

Good luck with your project.

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