Help with Site Layout

12 posts by 3 authors in: Forums > CMS Builder
Last Post: December 22, 2010   (RSS)

By pcolvin - November 22, 2010

I'm looking for some guidance on a site that I'm working on. I'll do my best to explain what I need help or guidance with.

I have built several smaller sites that used a separate .php file for each list or detail page such as index.php, about.php, links.php etc. This approach is fine for a smaller site, but the site I'm working on now would require 70 plus .php pages using that method. I would like to limit the number of .php viewer pages such as when using a Category Menu.

I would like to build the whole site with just one Category Menu, but here are my challenges. The site content will be managed by several users. Each user should only have access to the section, or Category Menu, they are responsible for. This approach will work, but then creates problems with the navigation menu. One of the goals is to enable the users to be able to create a new page (record in the Category Menu) and then be listed in the navigation menu. I can build the menu using foreach loops from several different Category Menu sections, see code below. However, since the detail viewer uses the number at the end of the URL, and each Category Menu section will have its own set of numbers, this may not be possible. It appears that each Category Menu section would need its own detail viewer .php page for this to work. This still means creating about 30 .php pages to do this.

If anyone has any suggestions or best practices on creating large sites that still provide granular access to manage the content while using as few .php page viewer files as possible, it would be much appreciated.

Thanks

Phil Colvin

<ul>
<?php foreach ($categoriesRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>

<ul>
<?php foreach ($categoryRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>

Re: [pcolvin] Help with Site Layout

By Chris - November 22, 2010

Hi Phil,

You can accomplish this by manually constructing your links instead of using the $record['_link'] feature. You can pass both the record num and the category menu it belongs to. For example:

<ul>
<?php foreach ($fooRecords as $record): ?>
<li><a href="detail.php?section=foo&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>

<ul>
<?php foreach ($barRecords as $record): ?>
<li><a href="detail.php?section=bar&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>


On your detail.php page, you'll need to do something like this:

list($myRecords, $myMetaData) = getRecords(array(
'tableName' => $_REQUEST['section'],
'where' => mysql_escapef('num = ?', $_REQUEST['num']),
'limit' => '1',
));
$myRecord = @$myRecords[0]; // get first record


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Help with Site Layout

By pcolvin - November 23, 2010

Chris,

I'm sure this will work, but I have a bit of a problem. It appears as though the link is being constructed properly:

https://www.sctfpa.org/content.php?section=categoriesRecords&num=3

However, the content.php page displays this error when displayed:

getRecords(categoriesRecords): Couldn't load schema for 'categoriesRecords'!

I'm pretty sure the code one the detail page (content.php) is correct, see below:

<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/sctf/htdocs/','','../','../../','../../../');
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($myRecords, $myMetaData) = getRecords(array(
'tableName' => $_REQUEST['section'],
'where' => mysql_escapef('num = ?', $_REQUEST['num']),
'limit' => '1',
));
$myRecord = @$myRecords[0]; // get first record


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


I'm sure it is something simple that I'm missing.

I do have another question, but I'll wait until we get this working before asking.

Thanks in advance.

Phil

Re: [pcolvin] Help with Site Layout

By pcolvin - November 23, 2010

Chris,

I found the problem. I was using categoriesRecords instead of categories which is the actual table name.

Now for the other question.

Would it be possible to construct a foreach loop to loop through all of the Category Menu sections that will be used to construct the navigation menu?

I'll have probably 20 plus Category Menu sections and instead of doing the following for each Category Menu Section, it would be nice to just loop through them one at a time and then nest the other foreach loop to build the menu items.

<ul>
<?php foreach ($categoriesRecords as $record): ?>
<li><a href="content.php?section=categories&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>

<ul>
<?php foreach ($categoryRecords as $record): ?>
<li><a href="content.php?section=category&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>


I hope what I'm asking makes sense. If not, let me know.

Thanks

Phil

Re: [pcolvin] Help with Site Layout

By Jason - November 24, 2010

Hi Phil,

In the code you showed, each of your foreach loops would output all of the records in categoryRecords. When you're talking about nesting foreach loops, do you mean outputting sub-categories?

If so, you can use something like this:

<ul>
<?php foreach($categoryRecords as $record):?>
<?php echo $record['_listItemStart'];?>
<a href="content.php?section=categories&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a>
<?php echo $record['_listItemEnd'];?>
<?php endforeach ?>
</ul>


Is this closer to what you're looking for?

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/

Re: [Jason] Help with Site Layout

By pcolvin - November 24, 2010

Jason,

I'll try to better explain what I'm trying to achieve.

The site will have multiple Category Menu sections that will be combined to build the site's menu. What I would like to do is loop through each of the Category Menu sections and then inside of that loop, loop through the records that will make up the menu items.

Here is what I'm doing now. At the top of the page, the code loads each of the tables for the Category Menu sections.

// load records

list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'categories',
));


list($categoryRecords, $categoryMetaData) = getRecords(array(
'tableName' => 'category',
));


I only have two sections setup right now for testing.

Below in the body of the page is where the code is to loop through each of the tables to grab the menu items.

<ul>
<?php foreach ($categoriesRecords as $record): ?>
<li><a href="content.php?section=categories&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>

<ul>
<?php foreach ($categoryRecords as $record): ?>
<li><a href="content.php?section=category&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>


Instead of having a separate foreach loop for each section, I was looking for a way to loop through each of the sections, then loop through the section's records.

<ul>

//Category Menu sections loop here

<?php foreach ($categoriesRecords as $record): ?>
<li><a href="content.php?section=categories&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>

//End Category sections loop here
</ul>
</li>


I hope this makes more sense.

Phil

Re: [pcolvin] Help with Site Layout

By Jason - November 25, 2010

Hi Phil

Okay, I think I better understand what you're trying to do. If you're going to be using multiple category and multiple multi-record sections, there isn't really going to be a good way of going about this other than to use a whole bunch of foreach loops.

You could consider having only 2 sections: 1 for all your categories, and 1 for your records. Each record in your record section would be associated with 1 category. In that way, you should be able to do all of this with only 2 foreach loops. Does this sound like something that would work for you?

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/

Re: [Jason] Help with Site Layout

By pcolvin - November 25, 2010

Jason,

Thanks for the reply and suggestion. One of my challenges is to have separate Category Menus to allow more granular control to multiple users so they can only edit the content that they are responsible for. If I'm correct, only having one Category Menu and a Multi Record section, I would not have the access control I need.

I probably should have used better names for the sections I was using for testing. My plan is to have something similar to this. These would all be created using Category Menus.

Executive Committee - Category Menu
- Subcommittee 1
- Subcommittee 2
- Subcommittee 3
Building Committee - second Category Menu
- Subcommittee 1
- Subcommittee 2
- Subcommittee 3

This pattern would go on for several more Category Menus with children records. My hope was to have a foreach loop that would loop through the Category Menu tables (parents) and then a nested loop to go through children records in each Category Menu to build the menu. I see the challenge with capturing the tables in an array to loop through. If that were possible, then it would be pretty simple to achieve. I suppose you don't have any ideas how to capture the actual tables in an array. I'm thinking the difficult part would be just capturing the tables from the database that you need instead of all of them. I could use a specific naming convention to filter them if it would be possible.

Thanks again for the help and suggestions.

Phil

Re: [Jason] Help with Site Layout

By Chris - November 25, 2010

Hi Phil,

How about something like this?

<?php
$categoryTablenames = array('section1', 'section2', 'section3', 'etc');

$categoryRecordSets = array();

foreach ($categoryTablenames as $tablename) {
list($categoryRecords,) = getCategories(array(
'tableName' => $tablename,
));
$categoryRecordSets[$tablename] = $categoryRecords;
}
?>

<ul>
<?php foreach($categoryRecordSets as $tablename => $categoryRecords): ?>
<li>
<ul>
<?php foreach ($categoryRecords as $record): ?>
<li><a href="content.php?section=<?php echo $tablename ?>&num=<?php echo $record['num'] ?>"><?php echo htmlspecialchars($record['name']) ?></a></li>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul>


Does that help? Please let me know if you have any questions.
All the best,
Chris