Hi,
I'm wondering if it's possible to create one category during my component installation.
It would be nice that my component has already his own category and be ready to use.
But the thing is that when a component category is created Joomla automaticaly add a new entry
in the __assets table wich looks pretty tricky to do manually.
I put some MySQL queries in the script.php and I made few trials but it doesn't work.
The creation of the category in the __categories table is ok, but the insert in the __assets
table fails. Joomla makes an insert for the new component and that's all, my query is ignored.
Is there any example somewhere, can someone helps me ?
Thanks.
Create a category during a component installation ?
Moderator: ooffick
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
-
- Joomla! Enthusiast
- Posts: 229
- Joined: Sun Jul 12, 2009 12:04 pm
-
- Joomla! Explorer
- Posts: 332
- Joined: Thu Aug 11, 2011 5:00 am
Re: Create a category during a component installation ?
Hi did you get any code to do this?
- fmmarzoa
- Joomla! Enthusiast
- Posts: 123
- Joined: Sun Nov 11, 2007 1:15 pm
- Location: Spain
- Contact:
Re: Create a category during a component installation ?
sh404 extension creates one. Perhaps installing it and examining its code may help you.
“The media's the most powerful entity on earth. They have the power to make the innocent guilty and to make the guilty innocent, and that's power. Because they control the minds of the masses.” -- Malcolm X
-
- Joomla! Intern
- Posts: 74
- Joined: Tue Jul 11, 2006 8:17 pm
Re: Create a category during a component installation ?
This is currently quite easy (I´m using the sh404sef extension way).
Here is a "snipplet" which you can use. This must be added to the script which is triggered during the component installation (in the helloworld.xml) via
add the following "snipplet" into the script.php in the installation section:
And voila ... some default categories added
Here is a "snipplet" which you can use. This must be added to the script which is triggered during the component installation (in the helloworld.xml) via
Code: Select all
<scriptfile>script.php</scriptfile>
Code: Select all
// Create categories for our component
$basePath = JPATH_ADMINISTRATOR . '/components/com_categories';
require_once $basePath . '/models/category.php';
$config = array( 'table_path' => $basePath . '/tables');
$catmodel = new CategoriesModelCategory( $config);
$catData = array( 'id' => 0, 'parent_id' => 0, 'level' => 1, 'path' => 'testentry', 'extension' => 'com_helloworld'
, 'title' => 'TestEntry', 'alias' => 'testentry', 'description' => '<p>This is a default test entry categorie</p>', 'published' => 1, 'language' => '*');
$status = $catmodel->save( $catData);
if(!$status)
{
JError::raiseWarning(500, JText::_('Unable to create default content category!'));
}
- inturias
- Joomla! Fledgling
- Posts: 3
- Joined: Sat Sep 26, 2009 3:02 pm
- Location: Bolivia
- Contact:
Re: Create a category during a component installation ?
Thanks a lot,
This information served me A LOT!!
This information served me A LOT!!
Leer, leer, leer...
-
- Joomla! Enthusiast
- Posts: 229
- Joined: Sun Jul 12, 2009 12:04 pm
Re: Create a category during a component installation ?
A bit late but thanks for this tip. It's very usefull.
However, I would advise to set parent_id to 1 (not to zero) as zero is
reserved to the ROOT category.
However, I would advise to set parent_id to 1 (not to zero) as zero is
reserved to the ROOT category.
-
- Joomla! Apprentice
- Posts: 18
- Joined: Tue Jul 28, 2009 3:32 pm
Re: Create a category during a component installation ?
how to add category and subcategory, when you don't know what Id will be of your category ?Biomehaniker wrote:This is currently quite easy (I´m using the sh404sef extension way).
Here is a "snipplet" which you can use. This must be added to the script which is triggered during the component installation (in the helloworld.xml) via
add the following "snipplet" into the script.php in the installation section:Code: Select all
<scriptfile>script.php</scriptfile>
And voila ... some default categories addedCode: Select all
// Create categories for our component $basePath = JPATH_ADMINISTRATOR . '/components/com_categories'; require_once $basePath . '/models/category.php'; $config = array( 'table_path' => $basePath . '/tables'); $catmodel = new CategoriesModelCategory( $config); $catData = array( 'id' => 0, 'parent_id' => 0, 'level' => 1, 'path' => 'testentry', 'extension' => 'com_helloworld' , 'title' => 'TestEntry', 'alias' => 'testentry', 'description' => '<p>This is a default test entry categorie</p>', 'published' => 1, 'language' => '*'); $status = $catmodel->save( $catData); if(!$status) { JError::raiseWarning(500, JText::_('Unable to create default content category!')); }