php – 以编程方式在Joomla中创建菜单项
发布时间:2020-12-13 17:13:29 所属栏目:PHP教程 来源:网络整理
导读:我在joomla 2.5中创建了一个组件,它创建了一篇新文章并将该文章添加到菜单项中. 创建文章工作正常,但我在创建菜单项时遇到了一些麻烦. 我有以下代码: //add the article to a menu item $menuTable = JTable::getInstance('Menu','JTable',array()); $menuD
我在joomla 2.5中创建了一个组件,它创建了一篇新文章并将该文章添加到菜单项中.
创建文章工作正常,但我在创建菜单项时遇到了一些麻烦. 我有以下代码: //add the article to a menu item $menuTable = JTable::getInstance('Menu','JTable',array()); $menuData = array( 'menutype' => 'client-pages','title' => $data[name],'type' => 'component','component_id' => 22,'link' => 'index.php?option=com_content&view=article&id='.$resultID,'language' => '*','published' => 1,'parent_id' => '1','level' => 1,); // Bind data if (!$menuTable->bind($menuData)) { $this->setError($menuTable->getError()); return false; } // Check the data. if (!$menuTable->check()) { $this->setError($menuTable->getError()); return false; } // Store the data. if (!$menuTable->store()) { $this->setError($menuTable->getError()); return false; } 错误似乎与设置parent_id和级别有关.在调试库/ joomla / database / tablenested.php时,将parent_id和level设置为0.这会在我的管理员页面上导致以下错误:
解决方法
尝试使用JTableNested :: setLocation($referenceId,$position =’after’):
$table->setLocation($parent_id,'last-child'); 我还认为你需要重建路径: // Rebuild the tree path. if (!$table->rebuildPath($table->id)) { $this->setError($table->getError()); return false; } 如果它仍然不起作用,试着找出你不做的MenusModelItem::save. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |