开发者

Building a custom CMS, how to handle page settings?

开发者 https://www.devze.com 2023-01-03 19:04 出处:网络
Not a coldfusion specific question so answer however you can. I\'ve inherited a ColdFusion project where at the top of every page various page-setting specific variables are set, such as:

Not a coldfusion specific question so answer however you can.

I've inherited a ColdFusion project where at the top of every page various page-setting specific variables are set, such as:

<cfset request.page.title = "Example Page">
<cfset request.page.machineTitle     = "example_page">
<cfset request.page.isJQueryEnabled  = 1>
<cfset request.page.showNavigation   = 1>
<cfset request.page.SWFObjectVersion = 2.2>

I'm thinking about creating a database table with just

integer page_id
varchar key
varchar value

I'd reduce the variables at the top of every page to just the page id, and then call the DB for the correct settings.

Is this a good idea? I hate reinventing the wheel, but this is a really big project that would require many months for a full content migration to a CMS.

What are the current practices for storing page settings? (e.g., what does WordPress do? Drupal? etc.)

---- Edit ----

Adding new features/page specific s开发者_高级运维cripts becomes a nightmare since I have to open every file and add/edit/remove a variable. There's no way to tell which pages are using what variables without opening them or using commandline (which I'm sure would inconvenience the other developers).

Also, what happens when I get a bunch of obsolete variables? E.g., eventually the "usePrototype" variable will be phased out and the entire site will be using jQuery.

Another method was to create and include a file with a giant switch block that sets these variables. This is done for some things already (e.g. meta tags-- switch on request.page.machine title, case xxx <meta tag whatever>). It's a mess.


If I understand what you're suggesting, you have a bunch of pages that have a line that sets the page title. You'd like to assign each page an identification number, and then remove the page title from the page, and then store it in a database instead. When you a user requests the page, instead of just using the page title in the page, instead you'd have to query the database by number for the page title.

If this is what you are suggesting, then the results will be:

  • longer page load times
  • increased database utilization and contention
  • reduced readability of the code (the page title can't be found without looking for it in a table)
  • increased chance of error (it's easy to mistake page 45 for page 54 when editing the table).

This would tend to make things less clear, instead of more clear.

I can't speak to Drupal, but Wordpress stores the entire page (or post) in a table, along with other metadata. Wordpress will combine the data in the table with a set of template files, and return a complate page to the user. The table will have a numeric key, but also has other non-primary key data that can be used to locate a given page (title, slug, category, tag, date, etc.)


In CF you have uber-cool Application.cfm (legacy) or Application.cfc (modern) templates. They are global. They are powerful. They are flexible (cfc much more).

  • You can pull global settings from DB and store into the Application scope for quick re-use.
  • You can read the per-page settings on each request and put into the needed scope request.page.
  • You can even read the information for all pages (use CGI scope to find out current page) and cache it in Application scope (or in built-in caching system -- available for CF9 and Railo).
  • You can temporarily cache information for already visited pages for quick re-use.


Calling from the Db isn't a bad idea as you will be centralising configuration. It depends a bit on your setup, but coldfusion should be able to cope with such a load.

Investigate Application.cfm or Application.cfc - when included at the root of a folder the code in these files gets called before your page gets run. As a result they can include common tasks, such as loading these variables. (Application.cfc is slightly more complex, but can also perform clean up work after a page has run).

You might be able to do the following to save you some time. Create an Application.cfc file (require Coldfusion MX7 or above) with an onReqestEnd method. In that method include code to save the currently set pages variables to the Db (if not previously saved). If pages don't already have an ID you can use CGI.varibles to pull back the current URL. Then as people view the pages they automatically get saved to the Db. Click round the site to ensure everything is saved. Install the code to pull back config in App.cfc onRequestStart method, and do a regexp find and replace to kill all the inline settings.

0

精彩评论

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