Small issue programaticaly creating categories for com_content

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
donkitter
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Aug 14, 2018 8:51 pm

Small issue programaticaly creating categories for com_content

Post by donkitter » Tue Aug 14, 2018 8:59 pm

Hello,

I am trying to programatically create content categories when a new user is created. I have the plugin working and it is creating the categories however the categories do not appear in some admin/editor drop downs unless I manually edit and save them. I assume I am missing a step in the creation process that maybe updates the associations or something. Would appreciate any insight. Thanks in advance and here is my code:

Code: Select all

    public static function createCategory($userId, $catName, $catAlias, $parentId, $rules)
    {

        $category_data['id'] = 0;
        $category_data['parent_id'] = $parentId;
        $category_data['created_user_id'] = $userId;
        $category_data['title'] = $catName;
        $category_data['alias'] = $catAlias;
        $category_data['extension'] = 'com_content';
        $category_data['published'] = 1;
        $category_data['language'] = '*';
        $category_data['params'] = array('category_layout' => '', 'image' => '');
        $category_data['metadata'] = array('author' => '', 'robots' => '');
        $category_data['associations'] = array();
        if(!is_null($rules)){
            $category_data['rules'] = $rules;
        }

        $basePath = JPATH_ADMINISTRATOR . '/components/com_categories';
        require_once $basePath . '/models/category.php';
        $config = array('table_path' => $basePath . '/tables');
        $category_model = new CategoriesModelCategory($config);
        if (!$category_model->save($category_data)) {
            $err_msg = $category_model->getError();
            return false;
        } else {
            $id = $category_model->getItem()->id;
            $category_model->checkin($id);
            return $id;
        }
    }


sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: Small issue programaticaly creating categories for com_content

Post by sozzled » Tue Aug 14, 2018 9:08 pm

Where is the method—the SQL command—used to create the new row in the _categories table?

donkitter
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Aug 14, 2018 8:51 pm

Re: Small issue programaticaly creating categories for com_content

Post by donkitter » Wed Aug 15, 2018 1:09 pm

sozzled wrote:
Tue Aug 14, 2018 9:08 pm
Where is the method—the SQL command—used to create the new row in the _categories table?
I used the model from /components/com_categories/models/category.php
to perform the save to the the database.

if (!$category_model->save($category_data)) {


Locked

Return to “Joomla! 3.x Coding”