![]() |
|
|||||||
| PHP - Code Snippets Functional Code Snippets that other people may find useful. Post them here! |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I found a tutorial online creating a dynamic menu from a mysql table. I created the table and inserted the data then created the functions on a form to create the menul. when I run the form I get the following error:
"Fatal error: Call to undefined function wp_dyn_menu() in C:\Documents and Settings\del\My Documents\Delphi for PHP Projects\WebPromotions\wp_header.php on line 45" Below is the code from the form, anyoone haave any ideas? <?php require_once("vcl/vcl.inc.php"); //Includes require_once("wp_data_module.php"); use_unit("dbctrls.inc.php"); use_unit("menus.inc.php"); use_unit("forms.inc.php"); use_unit("extctrls.inc.php"); use_unit("stdctrls.inc.php"); //Class definition class wp_header_form extends Page { public $Label1 = null; public $DBRepeater1 = null; public $Panel2 = null; public $HeaaderImage = null; public $Panel1 = null; public $MenuArray = array("id","label","link_url","parent_id"); function wp_header_formBeforeShow($sender, $params) { $dynmenuQuery = GetDBModule()->wp_dyn_menu_sql; $dynmenuQuery->Active = true; $str = ''; for($dynmenuQuery->First(); !$dynmenuQuery->EOF; $dynmenuQuery->Next()) { $MenuArray->id = $dynmenuQuery->id; $MenuArray->label = $dynmenuQuery->label; $MenuArray->link_url = $dynmenuQuery->link_url; $MenuArray->parent_id = $dynmenuQuery->parent_id; if ($MenuArray->parent_id == 0) { $parent_menu[$MenuArray->id]['label'] = $MenuArray->label; $parent_menu[$MenuArray->id]['link'] = $MenuArray->link_url; } else { $sub_menu[$MenuArray->id]['parent'] = $MenuArray->parent_id; $sub_menu[$MenuArray->id]['label'] = $MenuArray->label; $sub_menu[$MenuArray->id]['link'] = $MenuArray->link_url; $parent_menu[$MenuArray->parent_id]['count']++; } } echo wp_dyn_menu($parent_menu, $sub_menu, "menu", "nav", "subnav"); } function rebuild_link($link, $parent_var, $parent_val) { $link_parts = explode("?", $link); $base_var = "?".$parent_var."=".$parent_val; if (!empty($link_parts[1])) { $link_parts[1] = str_replace("&", "##", $link_parts[1]); $parts = explode("##", $link_parts[1]); $newParts = array(); foreach ($parts as $val) { $val_parts = explode("=", $val); if ($val_parts[0] != $parent_var) { array_push($newParts, $val); } } if (count($newParts) != 0) { $qs = "&".implode("&", $newParts); } return $link_parts[0].$base_var.$qs; } else { return $link_parts[0].$base_var; } } function wp_dyn_menu($parent_array, $sub_array, $qs_val = "menu", $main_id = "nav", $sub_id = "subnav", $extra_style = "foldout") { $menu = "<ul id=\"".$main_id."\">\n"; foreach ($parent_array as $pkey => $pval) { if (!empty($pval['count'])) { $menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n"; } else { $menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n"; } if (!empty($_REQUEST[$qs_val])) { $menu .= "<ul id=\"".$sub_id."\">\n"; foreach ($sub_array as $sval) { if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent']) { $menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\">".$sval['label']."</a></li>\n"; } } $menu .= "</ul>\n"; } } $menu .= "</ul>\n"; return $menu; } function Label1BeforeShow($sender, $params) { $sender->link = GetDBModule()->wp_main_menu->wp_menu_target; } function HeaaderImageBeforeShow($sender, $params) { $sender->ImageSource = GetDBModule()->wp_header_table->wp_header_image; } } global $application; global $wp_header_form; //Creates the form $wp_header_form=new wp_header_form($application); //Read from resource file $wp_header_form->loadResource(__FILE__); //Shows the form $wp_header_form->show(); |
| Sponsored Links |
|
|
|
|||
|
Thanks for the responce, I tried both and now am getting: "Fatal error: Call to a member function wp_dyn_menu() on a non-object in C:\Documents and Settings\del\My Documents\Delphi for PHP Projects\WebPromotions\wp_header.php on line 101"
|
|
|||
|
Thanks, with the two functions above the class decliration and no $this-> it does work but I do not have the sub menus. I will have to go back and check my data table and follow everything all the way through. Thanks, a lot for the help I am obviously new to D4PHP and PHP. I really apreciate the help.
|