Viewer pages don't show as soon as I add another viewer code...

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

By Izadorra - April 15, 2011

I know this has to be something really simple but I suck at programming so I can't figure out which character is giving me a problem.

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


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/nmcleanc/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($featured_storiesRecords, $featured_storiesMetaData) = getRecords(array(
'tableName' => 'featured_stories',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$featured_storiesRecord = @$featured_storiesRecords[0]; // get first record

// show error message if no matching record is found
if (!$featured_storiesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>

works. But when when I try to add another viewer to the page:

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


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/nmcleanc/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($featured_storiesRecords, $featured_storiesMetaData) = getRecords(array(
'tableName' => 'featured_stories',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$featured_storiesRecord = @$featured_storiesRecords[0]; // get first record

// show error message if no matching record is found
if (!$featured_storiesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>

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


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/nmcleanc/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($featured_storiesRecords, $featured_storiesMetaData) = getRecords(array(
'tableName' => 'featured_stories',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$featured_storiesRecord = @$featured_storiesRecords[0]; // get first record

// show error message if no matching record is found
if (!$featured_storiesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>

Does not work. I get a broken link error and the page doesn't show at all.

Re: [Izadorra] Viewer pages don't show as soon as I add another viewer code...

Hi Tzadorra,

You're probably better at coding then you think, you just need to get the hang of some basics, that's all.

First thing is, unless I don't understand what it is you're after, you shouldn't be calling the viewer_function and the records twice for the same featured_stories editor.

Try just using one of them, or event if you're actually trying to insert information from two different single record editors into the same web page, you still only have to load the viewer library once, so use something like:

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


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/nmcleanc/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 for first editor
list($featured_storiesRecords, $featured_storiesMetaData) = getRecords(array(
'tableName' => 'featured_stories',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$featured_storiesRecord = @$featured_storiesRecords[0]; // get first record

// optionally load records for the second editor
list($fsecond_editorRecords, $second_editorMetaData) = getRecords(array(
'tableName' => 'second_editor',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$second_editorRecord = @$second_editorRecords[0]; // get first record
//end optional load records code for the second editor
?>


Then from the code generator, put the echo code for the required fields where ever you want a particular field to be displayed.

You really don't need the error code stuff if you're sure there are records saved for both viewers.

That should get you closer to where you need to go.

There's a really thorough tutorial on CMSB coding basics (including sample exercises)and a lot of other really helpful recipes in my CMSB Cookbook http://www.thecmsbcookbook.com

Hope that works for you,

Don't give up...

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Viewer pages don't show as soon as I add another viewer code...

By Izadorra - April 15, 2011

Thank you! Works just the way I want it to.

Re: [Izadorra] Viewer pages don't show as soon as I add another viewer code...

By abincline - April 16, 2011

I also had trouble identifying which character is causing me the problem. I am not really good at programming but thanks to your post.