Re: Create category in install script

133 views
Skip to first unread message

elin

unread,
Jul 30, 2012, 1:50:21 PM7/30/12
to joomla-de...@googlegroups.com
You need to explicitly parent it to the com_example asset in the asset table. Since you're also creating that asset as part of the install process you should do that postflight.  You need to $table->getAssetByName('com_example')  and then in addition to the bind method from JTable you need to use the store method. 

Elin

On Monday, July 30, 2012 10:51:14 AM UTC-4, laoneo wrote:
According to the last forum post it is suggested I should ask here:

Hello
My component uses joomla core categories. On my component install script I want to create a default category for the component similar to the "Uncategorised" category of the content component. The code I run is as follows on the install script:
Code:
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');
$table = JTable::getInstance('Category', 'CategoriesTable');
$table->bind(array('title' => 'Uncategorised', 'extension' => 'com_example',
    'path' => 'uncategorised', 'alias' => 'uncategorised', 'published' => '1',
    'language' => '*');
$table->store();

The entry in the database has as level 0 and as parent_id 0 which looks like invalid. The calendar is shown on the category list but some warnings are displayed.

What is the correct way of creating a category in the code?

Thanks for any help 


here is the link to the question in the forum:

Michael Babker

unread,
Jul 30, 2012, 6:53:41 PM7/30/12
to joomla-de...@googlegroups.com
Try the code in this gist to help you out: https://gist.github.com/3211464

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/Ag5hJEMTrBcJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

laoneo

unread,
Jul 31, 2012, 2:28:00 AM7/31/12
to joomla-de...@googlegroups.com
Thanks worked like a charm with some small modifications check the comment on gist....
To post to this group, send an email to joomla-dev-general@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

elin

unread,
Jul 31, 2012, 5:49:35 AM7/31/12
to joomla-de...@googlegroups.com
Will you write that up for the wiki?

Elin

allon moritz

unread,
Jul 31, 2012, 7:56:55 AM7/31/12
to joomla-de...@googlegroups.com
where in the wiki?

To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/K8_zmARa6X8J.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.

elin

unread,
Jul 31, 2012, 1:28:14 PM7/31/12
to joomla-de...@googlegroups.com
You could do it as a FAQ if you want.

Elin
where in the wiki?

To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
Reply all
Reply to author
Forward
0 new messages