Thanks Boogyman!
Thanks Boogyman!
Is there some other code required to make that work?
I found this Smarty-related PHP code which if re-written might help the other code posted by boogyman:
Code:define('SITE_URL' = 'http://localhost/'); $smarty->assign('current_section', current_section()); $smarty->assign('primary_links', build_primary_links(); $smarty->display('index.tpl'); function current_section() { // For the purpose of this code, we'll keep this simple: return 'Home'; } function build_primary_links() { // this is also far more complex, but I'll keep this simple as well $primary_links = array('Home' => SITE_URL, 'News' => SITE_URL.'/?op=news', ); return $primary_links; }
boogyman broke the code. Without Smarty, it's:... assuming $pages is an array of "page" objects with "url" and "title" properties. It was mostly example pseudo-code though.Code:<?php foreach($pages as $page) { ?> <a href="<?php echo $page->url ?>"<?php if($page == $this_page) { ?> class="current"<?php } ?>> <?php echo $page->title; ?> </a> <?php } ?>
I really do recommend using a templating system for any reasonably-sized sites. PHP's default mix of data, logic, and presentation is a maintainability nightmare.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
This is my array... doesn't appear to be working though:
Code:<?php define('SITE_URL', 'http://localhost/'); // array(page_title => page_url) $pages = array('Home' => SITE_URL, 'News' => SITE_URL.'/news.php', 'Forum' => SITE_URL.'/forum', ); ?>
I said "objects," not "arrays."Code:class Page { public $title; public $url; private static $instances = array(); public static get_current() { foreach(self::$instances as $page) if($page->url === SITE_URL . $_SERVER['REQUEST_URI']) return $page; return false; } public Page($title, $url) { $this->title = $title; $this->url = $url; Page::$instances[] = $this; } } define('SITE_URL', 'http://localhost/'); $pages = array( new Page('Home', SITE_URL), new Page('News', SITE_URL . '/news.php'), new Page('Forum', SITE_URL . '/forum') ); $current_page = Page::get_current();
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Thanks Twey, but using that I get the following error message:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/bigbro/public_html/matthewmjscott/testingmenu.php on line 95
EDIT: I think the problem is that my server runs PHP4 and not PHP5 but I'm not entirely sure...
Last edited by matthewmjscott; 09-18-2007 at 10:45 AM.
Yeah. There's no missing curly braces, I think it's because I don't have PHP5. Thanks for your help anyway, I will recommend DD to my friends![]()
the php interpretter doesnt lie; it has nothing to do with which version of php you have installed
if you cannot find the mistake but would like help post your code encapsulated in [code][/code] tags
Last edited by Twey; 09-18-2007 at 01:42 PM. Reason: Removed dots.
Bookmarks