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  [ 9 posts ] 
Author Message
PostPosted: Sat Jan 15, 2011 4:14 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Dec 13, 2009 9:00 pm
Posts: 192
Location: Switzerland
Hi all

Someone knows how to create a default category like "Uncategorized" on install of a component?
I couldn't figure it out so far how this should be done correctly in my component.
I read somewhere something about a category.xml file we can use, but I didn't see any documentation about it. So maybe this was something discussed in Beta and got throwed out? I have no clue ;)


Top
 Profile  
 
PostPosted: Sat Jan 15, 2011 8:24 pm 
User avatar
Joomla! Guru
Joomla! Guru

Joined: Sun Feb 28, 2010 8:26 pm
Posts: 838
Location: Clarksville, TN
You could insert a SQL INSERT statement into the SQL install script for your component.

Code:
INSERT INTO `#__categories` VALUES
('', '', 1, '', '', 1, 'uncategorised', 'com_component', 'Uncategorised', 'uncategorised', '', '', 1, 0, '0000-00-00 00:00:00', 1, '{"target":"","image":""}', '', '', '{"page_title":"","author":"","robots":""}', 42, '2011-01-11 00:00:01', 0, '0000-00-00 00:00:00', 0, '*');

_________________
http://www.babdev.com
Unsolicited PMs will be ignored
Follow me @mbabker


Top
 Profile  
 
PostPosted: Sat Jan 15, 2011 8:51 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Dec 13, 2009 9:00 pm
Posts: 192
Location: Switzerland
That was my first thought as well, but then the assets table doesn't get populated which then raises all sorts of errors when you try to modifiy this category.
At least I believe it's related to the assets table entries.


Top
 Profile  
 
PostPosted: Sun Jan 16, 2011 11:23 am 
User avatar
Joomla! Guru
Joomla! Guru

Joined: Sun Feb 28, 2010 8:26 pm
Posts: 838
Location: Clarksville, TN
And you can't just insert an asset either because you have to recalculate the lft and rgt values for all parent items. You may need to include an install script with a function to insert the category, then the asset, then clean-up the asset table if you really want to include a category with your installation package.

_________________
http://www.babdev.com
Unsolicited PMs will be ignored
Follow me @mbabker


Top
 Profile  
 
PostPosted: Sun Jan 16, 2011 3:21 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Dec 13, 2009 9:00 pm
Posts: 192
Location: Switzerland
Yes, I think so.
I guess there should be a Core function to do that, which could be called on install.
I see there is a new JCategories class in the core, but it doesn't look like it offers a function to do what I would need.

Or am I the only one who wants to create a default category for my component on install? All the Core applications seem to do this as well, but their life is easier :)


Top
 Profile  
 
PostPosted: Thu Mar 03, 2011 9:37 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Aug 06, 2010 4:17 pm
Posts: 5
Did you find a solution yet? I am having the same problem.


Top
 Profile  
 
PostPosted: Thu Mar 03, 2011 10:04 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Dec 13, 2009 9:00 pm
Posts: 192
Location: Switzerland
No


Top
 Profile  
 
PostPosted: Tue Apr 05, 2011 12:14 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Dec 01, 2010 2:02 pm
Posts: 7
Location: Sweden
I'm stuck with the same problem. Please help someone!


Top
 Profile  
 
PostPosted: Tue May 01, 2012 7:10 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Apr 17, 2009 1:30 am
Posts: 31
I came across your post when I was looking for the same thing. I'm pretty new at Joomla development, but I think I've got it worked out.

You need to create an installation script and then create the category in there. Something like this...

Code:
    /**
     * method to install com_whatever
     *
     * @param   JInstallerFile   $installer   The class calling this method
     *
     * @return void
     */
    public function install($installer)
    {
        // Create "uncategorised" category for 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' => 'uncategorised', 'extension' => 'com_whatever',
            'title' => 'Uncategorised', 'alias' => 'uncategorised',
            'description' => '', 'published' => 1, 'language' => '*');
        $status = $catmodel->save($catData);

        if(!$status)
        {
            JError::raiseWarning(500, JText::_('Unable to create default content category!'));
        }
    }


And of course make sure you replace "whatever" with your component name (or whatever).

I hope that helps!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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