如何从PHP脚本中删除Joomla中的嵌套类别

时间:2016-04-15 21:09:16

标签: php joomla

我想开发我的应用程序以获得更好的功能。我需要在Joomla中使用PHP脚本删除一类文章。例如我有一个主要类别和子类别。如何删除选定的子类别然后运行rebuild?而是使用Joomla管理员,我想使用自己的脚本。

我使用以下示例代码创建新的子类别:

<?php

   define( '_JEXEC', 1 );
   define('JPATH_BASE', '../');
   define( 'DS', DIRECTORY_SEPARATOR );

   require_once ( JPATH_BASE . 'includes'.DS.'defines.php' );
   require_once ( JPATH_BASE . 'includes'.DS.'framework.php' );
   require_once ( JPATH_ADMINISTRATOR .DS. 'components'.DS.'com_categories'.DS.'models'.DS.'category.php');

   $mainframe =& JFactory::getApplication('site');
   $mainframe->initialise();

   $extension = 'com_content';
   $title     = 'nowa';
   $parent_id = 9;

// JTableCategory is autoloaded in J! 3.0, so...
if (version_compare(JVERSION, '3.0', 'lt'))
{
   JTable::addIncludePath(JPATH_PLATFORM . 'joomla/database/table');
}

// Initialize a new category
$category = JTable::getInstance('Category');
$category->extension = $extension;
$category->title = $title;
$category->published = 1;
$category->access = 1;
$category->params = '{"category_layout":"","image":""}';
$category->metadata = '{"author":"","robots":""}';
$category->language = '*';

// Set the location in the tree
$category->setLocation($parent_id, 'last-child');

// Check to make sure our data is valid
if (!$category->check())
{
   JError::raiseNotice(500, $category->getError());
   return false;
}

// Now store the category
if (!$category->store(true))
{
   JError::raiseNotice(500, $category->getError());
   return false;
}

// Build the path for our category
$category->rebuildPath($category->id);

当我运行此代码时,我收到带有资产表的新子类别。 我希望删除任何类别。

0 个答案:

没有答案