PHP Code or CMSB PHP Code?

5 posts by 3 authors in: Forums > CMS Builder
Last Post: May 5, 2011   (RSS)

By Perchpole - May 3, 2011 - edited: May 3, 2011

Much of what I know about PHP has come from my association with CMSB and this forum. As a result my approach to PHP is very CMSB-centric! I don't know if the way I go about constructing code is typical or if I'm just copying the CMSB style - without even knowing it!

Take list() functions.

In CMSB it's normal to park all the list() functions at the top of the page. This seems fine if you're dealing with a simple site which only draws on a limited number of records.

What about a more complex site? What happens when the lists get into double figures? I'm guessing there must be a price to pay?

Should I be thinking about putting some kind of conditional code around these functions? Surely, if the records they call aren't required on every page then I could free-up precious resources by switching them off until they are?

Alternatively, should I consider putting the list() functions into the actual page code itself? That way the records wouldn't be called until a particular page element is loaded.

I'm guessing there are 3 factors at play here:
  • Overhead

  • Security

  • Best Practice

Perhaps people could share their experience and give me some advice.

Thanks,

:0)

Perchpole

Re: [Perchpole] PHP Code or CMSB PHP Code?

By Dave - May 3, 2011

Hi Perch,

In general my advice is usually to not even worry about performance issues until they become an issue or you know from past experience they will. Most of the time performance won't be an issue or there will be other issues that come up first (like the max number of simultaneous connections you web host allows, etc).

As for loading 10+ sections at the top of the page, I'd be curious how your structuring your sections. Maybe there is a way to combine some of them?

If you have a viewer you can attach that has a lot of code at the top I'd be happy to take a look and see if I could offer any suggestions.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] PHP Code or CMSB PHP Code?

By Perchpole - May 5, 2011

Hi, CHaps -

Thanks for your help.

My initial query is as result of my preference to develop CMSB websites through only a single page. I've created a number of portals using this approach already - some fairly complex - and I think the results can be very effective, not to say lean!

The idea is that everything is rendered through a single index.php page which sits in the root of the site. The various page layouts and other elements are pulled in as includes, which are either assigned manually or triggered by a strict $selectedCategory framework.

It works a treat.

The only downside is the list() and getRecords() functions mentioned above. As I'm only using a single output page, it has to include the complete list of getRecords() calls for the entire site - even though only one or two are actually in use at any one time. That's why I wondered if I should look at introducing some kind of conditional on/off system so that the calls are only made when a particular record/category requires them.

:os

Perch

Re: [Perchpole] PHP Code or CMSB PHP Code?

By Jason - May 5, 2011

Hi Perch,

For the situation you describe, it might be a good idea to put your getRecords() calls inside your include files. This would mean that you're only making the calls you need and will help to keep your code cleaner so it's easier to find what you need.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/