开发者

Where should I place text that I'm trying to abstract in my CakePHP application?

开发者 https://www.devze.com 2023-01-11 04:22 出处:网络
I am writing a CakePHP application and am trying to have tex开发者_JAVA技巧t that is frequently displayed (or particularly long) saved in a config file somewhere that we can easily edit it.

I am writing a CakePHP application and am trying to have tex开发者_JAVA技巧t 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?


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).


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.


...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.

0

精彩评论

暂无评论...
验证码 换一张
取 消