Superfluous code?

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 7, 2010   (RSS)

By roddruce - May 7, 2010

Hello all,

Is all the code below required? I am only using the content code line for this page.

<?php echo $aboutRecord['content'] ?>

Are lines beginning with forward slashes required?

Also is this line of code needed? header("HTTP/1.0 404 Not Found");

Rod

______________________________________________________________

<?php header('Content-type: text/html; charset=utf-8'); ?>

<?php

// load viewer library

$libraryPath = 'cmsAdmin/lib/viewer_functions.php';

$dirsToCheck = array('/home/vintager/public_html/','','../','../../','../../../');

foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}

if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records

list($aboutRecords, $aboutMetaData) = getRecords(array(

'tableName' => 'about',

'where' => whereRecordNumberInUrl(1),

'limit' => '1',

));

$aboutRecord = @$aboutRecords[0]; // get first record

// show error message if no matching record is found

if (!$aboutRecord) {

header("HTTP/1.0 404 Not Found");

print "Record not found!";

exit;

}

?>


Re: [roddruce] Superfluous code?

By Jason - May 7, 2010

Hi,

Most of what you have is necessary. Lines that begin have /* or // are comments. They are not executed code, but are used to tell a developer what a block of code is for. You could remove them if you wanted, but it won't affect how your page loads.

This section:
if (!$aboutRecord) {

header("HTTP/1.0 404 Not Found");

print "Record not found!";

exit;

}


Tell's the server what to do if there is no record found.

The rest of the code you've posted is code CMS Builder uses to link to it's viewer library, and retrieve your records from the database.

Besides the comments, there really isn't anything extra here.

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/