in Joomla

Adding custom fields to ‘any’ joomla component’s any view

I was finding is there any way to add custom fields to joomla core component (please don’t start discussing about other 3rd party has those options built in as I know them and I wanted this with core joomla, btw, I didn’t check the tables for j3.2 yet)

Found this in joomla docs

where they showed an example how to use the #__user_profiles table where custom or extra user fields are stored.

This seems funny to me what will happen when someone add custom field for user id suppose 321 and same way article id 321 ? !

Current structure of the #__user_profiles table is

I think we need something like

CREATE TABLE IF NOT EXISTS `#__cbcustompostmeta` (
  `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  `component` varchar(255) DEFAULT NULL,
  `meta_key` varchar(255) DEFAULT NULL,
  `meta_value` longtext,
  PRIMARY KEY (`meta_id`),
  KEY `post_id` (`post_id`),
  KEY `meta_key` (`meta_key`)

This table sql is little modified from wordpress meta table. I added the extra col ‘component’.

The good use of this table structure is post_id can be used to store any component’s any single view (article , category, event, contact etc) id (means article id, event id, or category id)

for ‘component’ col value should be inserted following this convension “com_content.article” , we need to use the view name with component as for same component we may need to add custom fields for different view like for event component event and venue both are treated as single article .

What do you think ?