I'm a beginner in web development and so with Joomla!. I'm creating a module in order to speed up article publishing. I need to add programmatically articles and tags. I managed to upload articles with this code I copied out of somewhere:
Code: Select all
function addArticle($title, $filename){
$article = JTable::getInstance('content');
$article->title = $title;
$article->alias = JFilterOutput::stringURLSafe($title);
$article->introtext ='text';
$article->catid = 15; //pages
$article->created = JFactory::getDate()->toSQL();
$article->created_by_alias = 'Super User';
$article->state = 1;
$article->access = 1;
$article->metadata = '{"page_title":"","author":"","robots":""}';
$article->language = '*';
if (!$article->check()) {
JError::raiseNotice(500, $article->getError());
return FALSE;
}
if (!$article->store(TRUE)) {
JError::raiseNotice(500, $article->getError());
return FALSE;
}
return TRUE;
}
Code: Select all
$article = JTable::getInstance('content');
And when i'm trying to do the same thing for tags:
Code: Select all
function addTag($tagName){
$tag = JTable::getInstance('tags');
$tag->path = JFilterOutput::stringURLSafe($tagName);
$tag->title = $tagName;
$tag->level = 1;
$tag->alias = JFilterOutput::stringURLSafe($tagName);
$tag->published = 1;
$tag->publish_up = JFactory::getDate()->toSQL();
$tag->version = 1;
$tag->language = '*';
$tag->access = 1;
$tag->created_time = JFactory::getDate()->toSQL();
if (!$tag->check()) {
JError::raiseNotice(500, $tag->getError());
return FALSE;
}
if (!$tag->store(TRUE)) {
JError::raiseNotice(500, $tag->getError());
return FALSE;
}
return TRUE;
}
I got the error .check() method doesn't exist. I don't understand why: is there a diffence between these two functions ? In both cases I'm adding a row in a SQL database.
Thank you for any help in understanding the problem.
PS: English isn't my native language please excuse me if some sentences sound weird.
EDIT: is there a way to display the code with colors ?