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!
Labels |
Added:
?
|
Category | ⇒ | com_content |
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-09-15 13:33:49 |
Closed_By | ⇒ | brianteeman |
The best place to ask this is https://groups.google.com/forum/#!forum/joomla-dev-general