?
avatar ztj1993
ztj1993
15 Sep 2017

I need to update the article content through code, Here is my code:

$aid='1';
$articletext='new content';
$this->ContentTable = JTable::getInstance('Content', 'JTable');
$this->ContentTable->load($aid);
$this->ContentTable->save(array('articletext' => $articletext));

or

JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/models');
JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_content/models/forms');
$this->ArticleModel = JModelLegacy::getInstance('Article', 'ContentModel', array());
$form = $this->ArticleModel->getForm();
$form->bind(array('articletext' => $articletext));
$validData = $this->ArticleModel->validate($form, $form->getData()->toArray());
$this->ArticleModel->save($validData);

Both of these two methods lead to data loss, especially the loss of tag data. Do you have any good suggestions? Best to simulate the normal data storage, you can very well implement the Joomla event program!


The above is about software translation!

avatar ztj1993 ztj1993 - open - 15 Sep 2017
avatar joomla-cms-bot joomla-cms-bot - change - 15 Sep 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Sep 2017
avatar ztj1993 ztj1993 - change - 15 Sep 2017
The description was changed
avatar ztj1993 ztj1993 - edited - 15 Sep 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 15 Sep 2017
Category com_content
avatar brianteeman
brianteeman - comment - 15 Sep 2017
avatar brianteeman brianteeman - change - 15 Sep 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-09-15 13:33:49
Closed_By brianteeman
avatar brianteeman brianteeman - close - 15 Sep 2017

Add a Comment

Login with GitHub to post a comment