Loading Different Page Content Without Query Strings
2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 5, 2013 (RSS)
Hello, All
In the past I've always relied on query strings to load page templates and content. In my latest CMSB deployment, however, such methods will not work so I am trying to find a sightly different approach.
I want to load the page template and content based on the php page/file name.
For example, if the URL is:
http://www.mysite.com/about.php
Then I can use the following code to work out the file name:
$path = $_SERVER["SCRIPT_NAME"];
$file = basename($path); //$file is set to "about.php"
I could now use various "if" constructs to match the $file and load the required content.
Is this the right approach? What would be the best way of achieving this in terms of the lowest overhead?
:0/
Perchpole
By Jason - September 5, 2013
Hi,
You can certainly take that approach. You shouldn't run into too much of an issue in terms of overhead. One of the problems you may run into is the code base would become quite large as new pages are being added as you would need to keep adding to your if statement. Another approach you could take is to put the code that loads the content directly on the individual pages.
For example, on about.php, we know what content we would want to load, so we can hardcode in the getRecords call for that page.
Hope that 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/