Re: Storing multiple categories values in Database ?

291 views
Skip to first unread message

Matias Aguirre

unread,
Jul 31, 2012, 3:37:21 AM7/31/12
to joomla-de...@googlegroups.com
Try setting the extension into the xml

        <field
            name="catid"
            type="category"
            extension="com_xyz"
            class="inputbox"
            multiple="true"
            label="COM_XYZ_FIELD_CATID_LABEL"
            description="COM_XYZ_FIELD_CATID_DESC"
            required="true"
        >

On Tuesday, 31 July 2012 03:28:07 UTC-3, Prashant Sudeep wrote:
Hi,

I am trying to build a component in Joomla where I want an item to be in multiple categories.

Whenever I select ]multiple=multiple in xml form, and Submit the form, catid is set to zero.
<field
name="catid"
multiple="multiple"
type="category">
<option value="0">JOPTION_SELECT_CATEGORY</option>
</field>
How do I achieve that?

Secondly where is code to insert catid values in db.
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_xyz.edit.xyz.data', array());
if (empty($data))
{
$data = $this->getItem();
}
print_r($data);
return $data;
}



Can anyone help me out in this...

Regards
Prashant

elin

unread,
Jul 31, 2012, 6:04:15 AM7/31/12
to joomla-de...@googlegroups.com

An item cannot be in multiple categories. Categories uses a strict tree structure. Com_categories is not going to let you save that way.

Elin

On Tuesday, July 31, 2012 3:55:19 AM UTC-4, Prashant Sudeep wrote:
I have tried that too.but its not working....

Mike Azores

unread,
Sep 2, 2012, 11:34:13 AM9/2/12
to joomla-de...@googlegroups.com
Hi,
If I make a component, say com_mycomponent and define a DB table for that component witch one field is for recording a set of categories the item belongs to (using jRegistry), should I define a custom field to get the categories of that component and let the user (site admin) select the desired categories (more than one if he wants that)? 

I mean, if I create the categories for my component using Joomla facilties then, can I use those categories in my component the way I want (ie. having more than 1 category assign to my com_mycomponent item) ?

Cheers.

Mike

elin

unread,
Sep 2, 2012, 6:47:35 PM9/2/12
to joomla-de...@googlegroups.com

Joomla categories use a hierarchical tree structure (and nested sets) and every single element of their existence from controlling who has permission to do what to determining the effective state to rendering the categories view to rendering the parent and child links in other views is build on this assumption.

If you want to do non hierarchical classification you need to use another system. 

Elin

Herman Peeren

unread,
Sep 3, 2012, 2:27:49 AM9/3/12
to joomla-de...@googlegroups.com
Hi Mike,

I think it is very interesting what you try to accomplish! The way you want to store multiple categories is certainly possible; other possibilities are JSON in that categories-field or a separate table (1NF). The only thing that is not possible is to use the ACL for the categories then, but I assume that is not a problem (for it is not very useful to use category-level ACL if you are using multiple categories). If you want to use ACL on the item-level, then just use your component as parent-asset, not the categories.

A tree is a graph with every node having exactly 1 parent. When having multiple parents in a graph (a Directed Acyclic Graph, DAG) you can always be split into multiple trees (with partial identical content). In fact, that is what you do when you store multiple category-ids. In that way you can still use the category tree system that we have in Joomla. It would be interesting however to implement some more general graph handling of which a tree is just a special case.

I like to keep in touch about this project, for I see some interesting possibilities for the future. I'm curious.

Best regards,
Herman Peeren

Mike Azores

unread,
Sep 3, 2012, 5:06:20 AM9/3/12
to joomla-de...@googlegroups.com
@Herman, @Elin, thanks both for your feedback.

My main motivation to use Joomla Categories in my component is to avoid build my custom category system (adding new tables, admin menu, etc.) I'm okay if using Joomla Categories (assigning >1 categories to my component items) forces me to loose ACL for the categories inside my component. 

I'm glad it is possible to do that!! :) I'm willing to try it and will keep this thread updated with relevant info.

Best regards.

Mike

Herman Peeren

unread,
Sep 3, 2012, 5:35:54 AM9/3/12
to joomla-de...@googlegroups.com
Yet another possibility to use existing Joomla! software to get those "multiple categories" is to extend from JTableNested. That is Joomla's abstract table for tree-like content.The categories are extended from that too. When making your own "multi-categories" you also avoid confusion with the standard categories in Joomla!. But the downside of this is, that you might end up with a lot of duplicate code. So I think it is best to first investigate how much you can use from the existing categories; I think the first thing is to list what things have to be adjusted.

One of the things you wanted to re-use is the admin menu for categories, but you'll have to adjust or partly rebuild that to be able to use multiple categories. I'll also experiment a bit with that (and let it know here what I find).

Ciao,
Herman

Herman Peeren

unread,
Sep 3, 2012, 6:37:37 AM9/3/12
to joomla-de...@googlegroups.com
Sorry, you don't have to rebuild any admin-part for the categories. That stays the same.

I think you only have to change the possibility to choose multiple categories in the item's edit form an then store those multiple category_ids. And of course when displaying the content you'll have to retrieve the list of categories this item belongs to. For the rest I do'n see any changes or problems. You could even still use a category-blog-view exactly as you do with single category items.

So, that doesn't seem to be too difficult.

allon moritz

unread,
Sep 3, 2012, 6:53:21 AM9/3/12
to joomla-de...@googlegroups.com
Please share your solution here...I need also a multiple categories field in my menu item :-)


--
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/-/MD1Kxy_3do8J.

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.

Mike Azores

unread,
Sep 3, 2012, 6:54:59 AM9/3/12
to joomla-de...@googlegroups.com
This is exactly how I thought to build it. Thanks for the feedback as I'm not too familiar with 2.5 API. I'm now more confident on building that!
I think I will use a custom jField to select the multi categories in the forms (add / edit)...
Cheers. Mike

Mike Azores

unread,
Sep 3, 2012, 6:59:31 AM9/3/12
to joomla-de...@googlegroups.com
When I get something I will share it here. However I'm not sure if what I'm doing will fit your purposes. I'm making a custom component and I'm not sure if you pretend to build a custom component and assign multi categories to each item of that custom component...
Cheers. Mike


El lunes, 3 de septiembre de 2012 12:53:44 UTC+2, laoneo escribió:
Please share your solution here...I need also a multiple categories field in my menu item :-)

On Mon, Sep 3, 2012 at 12:37 PM, Herman Peeren <herman...@gmail.com> wrote:
Sorry, you don't have to rebuild any admin-part for the categories. That stays the same.

I think you only have to change the possibility to choose multiple categories in the item's edit form an then store those multiple category_ids. And of course when displaying the content you'll have to retrieve the list of categories this item belongs to. For the rest I do'n see any changes or problems. You could even still use a category-blog-view exactly as you do with single category items.

So, that doesn't seem to be too difficult.

--
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/-/MD1Kxy_3do8J.

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

Herman Peeren

unread,
Sep 3, 2012, 6:59:39 AM9/3/12
to joomla-de...@googlegroups.com
@Mike: yes, a multi-select JField for those categories, that would be my starting point too.

Adam Rifat

unread,
Sep 3, 2012, 6:59:54 AM9/3/12
to joomla-de...@googlegroups.com
How could this work with multi languages?

Herman Peeren

unread,
Sep 3, 2012, 7:02:28 AM9/3/12
to joomla-de...@googlegroups.com
On Monday, 3 September 2012 12:53:44 UTC+2, laoneo wrote:
Please share your solution here...I need also a multiple categories field in my menu item :-)

Solutions will be posted here. But it is for a custom component and cannot be just used for existing core components.

Herman Peeren

unread,
Sep 3, 2012, 7:07:26 AM9/3/12
to joomla-de...@googlegroups.com
On Monday, 3 September 2012 12:59:54 UTC+2, Adam Rifat wrote:
How could this work with multi languages?

What is the problem with multi languages? 

allon moritz

unread,
Sep 3, 2012, 9:00:59 AM9/3/12
to joomla-de...@googlegroups.com
no problem :-)

--
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/-/KjUeOSOrIpAJ.

Chris Davenport

unread,
Sep 3, 2012, 2:58:34 PM9/3/12
to joomla-de...@googlegroups.com
I haven't had time to read the whole of this thread, so I might be missing the point, but I'd just like to suggest that you consider using Smart Search for this.

Putting items into multiple categories is really just a form of tagging.  So just create a Smart Search plugin for your content type and allow the user to "tag" each item with as many tags as they want.  Then you can either set up a (static) filter to filter on those tags or use the regular (dynamic) filters.  The tags themselves might have a strict hierarchical structure if you want that (to support the user interface maybe), but Smart Search doesn't need to know about it.

Just a thought.

Chris.
--
Chris Davenport
Joomla Production Leadership Team

Herman Peeren

unread,
Sep 3, 2012, 3:16:40 PM9/3/12
to joomla-de...@googlegroups.com
Wow, thanks Chris. What a possibilities we have in Joomla!.

I didn't know this. Guess I have to read through those documents: http://docs.joomla.org/index.php?search=smart+search&go=Go&title=Special%3ASearch to know more ab out it.

Herman

Chris Davenport

unread,
Sep 3, 2012, 3:20:15 PM9/3/12
to joomla-de...@googlegroups.com
http://docs.joomla.org/Category:Smart_Search

Chris.

--
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/-/8HyKwoFf3jcJ.

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.

Mike Azores

unread,
Sep 3, 2012, 5:07:50 PM9/3/12
to joomla-de...@googlegroups.com
Thanks for the suggestion Chris. Great stuff!!! I was looking for this as I am/was planning to build a custom tag system. 
Having read the documentation about Smart Search I have some concerns about performance. My site will get around 1000 events (custom component I'm developing), 60 item from my other custom component and around 700 joomla articles. I wondering if this is considered a BIG site to be handled by Smart Search...

Regarding my other custom component being developed using Joomla Categories (the one that leads to open this thread), one of my objectives of using Joomla Categories is also to use the info stored in a Category item (description, metatag, etc) inside my custom component. Ie. display a view with all this categories listed of my custom component. If the user selects one category, it should display all the items (from my custom component) associated with that category. 

In this component, I was additionally considering adding tag capability. I think (if performance shouldn't be a big deal) that Smart Search should take care of this... Any thought would be welcome.

Best regards.

Mike

El lunes, 3 de septiembre de 2012 21:20:18 UTC+2, Chris Davenport escribió:
On 3 September 2012 20:16, Herman Peeren <herman...@gmail.com> wrote:
Wow, thanks Chris. What a possibilities we have in Joomla!.

I didn't know this. Guess I have to read through those documents: http://docs.joomla.org/index.php?search=smart+search&go=Go&title=Special%3ASearch to know more ab out it.

Herman



On Monday, 3 September 2012 20:58:38 UTC+2, Chris Davenport wrote:
I haven't had time to read the whole of this thread, so I might be missing the point, but I'd just like to suggest that you consider using Smart Search for this.

Putting items into multiple categories is really just a form of tagging.  So just create a Smart Search plugin for your content type and allow the user to "tag" each item with as many tags as they want.  Then you can either set up a (static) filter to filter on those tags or use the regular (dynamic) filters.  The tags themselves might have a strict hierarchical structure if you want that (to support the user interface maybe), but Smart Search doesn't need to know about it.

Just a thought.

Chris.

--
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/-/8HyKwoFf3jcJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@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