2

I have seen this post and it was really helpful

Create categories, subcategories and articles using php

but I am not able to create articles by using same script.

I have modified the script but everytime its giving me this error

Call to undefined method CategoriesHelper::validateCategoryId()

Is there any other way to create bulk articles or add data to the joomla #__content table??

3

I also faced the similar issue once and I modified the code as following which worked for me. You also need to pass the access and metadata in the article parameters.

$article_data = array(
    'id' => 0,
    'catid' => 2,
    'title' => 'My article title',
    'alias' => 'my-article-alias',
    'introtext' => 'My intro text',
    'fulltext' => 'My full text',
    'state' => 1, //if you want to keep the article published else 0
    'alias' => 'my-article-alias',
    'state'=>1,
    'language' => '*',
    'access' => 1,
    'metadata' => json_encode(array('author' => '', 'robots' => ''))
);

$article_id = createArticle($article_data);
if(!$article_id){
    echo "Article create failed!";
}
else{
    echo 'Article created';
}

function createArticle($data)
{
    $data['rules'] = array(
        'core.edit.delete' => array(),
        'core.edit.edit' => array(),
        'core.edit.state' => array(),
    );

    $basePath = JPATH_ADMINISTRATOR.'/components/com_content';
    require_once $basePath.'/models/article.php';
    $article_model =  JModelLegacy::getInstance('Article','ContentModel');
    // or  $config= array(); $article_model =  new ContentModelArticle($config);
    if(!$article_model->save($data)){
        $err_msg = $article_model->getError();
        return false;
    }else{
        $id = $article_model->getItem()->id;
        return $id;
    }

}

Note: For static, it will work only once as article article alias needs to be unique.

Hope this helps.

  • Glad it helped :) – Liz. Aug 23 '16 at 6:46
0

You can import data to the #__articles table in phpMyAdmin using a CVS import.

Note that the entries created in the #__assets table are not necessary to the stability of the website - we run many many Joomla websites where the articles have no associated entries in the #__assets table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.