The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Aug 06, 2011 2:47 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Jul 12, 2009 12:04 pm
Posts: 204
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.


Top
 Profile  
 
PostPosted: Mon Jan 16, 2012 9:50 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Thu Aug 11, 2011 5:00 am
Posts: 324
Hi did you get any code to do this?


Top
 Profile  
 
PostPosted: Mon Jan 16, 2012 11:20 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Nov 11, 2007 1:15 pm
Posts: 123
Location: Spain
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


Top
 Profile  
 
PostPosted: Thu Feb 09, 2012 10:16 am 
Joomla! Intern
Joomla! Intern

Joined: Tue Jul 11, 2006 8:17 pm
Posts: 63
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

Code:
  <scriptfile>script.php</scriptfile>


add the following "snipplet" into the script.php in the installation section:

Code:
      // 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!'));
    }


And voila ... some default categories added :pop


Top
 Profile  
 
PostPosted: Thu May 03, 2012 5:33 am 
User avatar
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Sep 26, 2009 3:02 pm
Posts: 3
Location: Bolivia
Thanks a lot,

This information served me A LOT!!

_________________
Leer, leer, leer...


Top
 Profile  
 
PostPosted: Wed Mar 27, 2013 9:49 am 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Jul 12, 2009 12:04 pm
Posts: 204
A bit late but thanks for this tip. It's very usefull. ;D
However, I would advise to set parent_id to 1 (not to zero) as zero is
reserved to the ROOT category.


Top
 Profile  
 
PostPosted: Fri Sep 20, 2013 12:46 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Jul 28, 2009 3:32 pm
Posts: 18
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

Code:
  <scriptfile>script.php</scriptfile>


add the following "snipplet" into the script.php in the installation section:

Code:
      // 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!'));
    }


And voila ... some default categories added :pop

how to add category and subcategory, when you don't know what Id will be of your category ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 



Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group