No Code Attached Yet
avatar David2376
David2376
26 Jul 2021

Steps to reproduce the issue

use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
$table = Table::getInstance('Content', 'JTable');

$data = array();
$data['title'] = "something";
$data['alias'] = "something";
$data['state'] = 1;
$data['catid'] = 1;
.....

// Bind data
if (!$table->bind($data)) {
throw new Exception($table->getError());
}

// Save Article
if (!$table->store()) {
throw new Exception($table->getError());
}

Expected result

The article should be saved in the #__content table and viewable from the admin backend.

Actual result

The article is saved to the #__content table. The #__assets table appear to be populated correctly. However, the article IS NOT visible in the admin backend.

System information (as much as possible)

Joomla 4.0.0-rc4

Additional comments

avatar David2376 David2376 - open - 26 Jul 2021
avatar joomla-cms-bot joomla-cms-bot - labeled - 26 Jul 2021
avatar joomdonation
joomdonation - comment - 26 Jul 2021

The code you are using is not recommended/standard way to save an item. What you should do is create model object and use save method to save the object.

Sample code https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_categories/src/Helper/CategoriesHelper.php#L97

For your case, create article, you can try this (not tested):

$model = Factory::getApplication()->bootComponent('com_content')
			->getMVCFactory()->createModel('Article', 'Administrator', ['ignore_request' => true]);

$model->save($data);
$id = $model->getState('article.id');
avatar David2376 David2376 - change - 26 Jul 2021
Title
Issue Saving Articles Using getInstance (Articles Saved To DB but not viewable in backend)
Issue Saving Articles Using Joomla\CMS\Table\Table (Articles Saved To DB but not viewable in backend)
avatar David2376 David2376 - edited - 26 Jul 2021
avatar joomdonation
joomdonation - comment - 22 Aug 2021

Closing this issue is not something with Joomla core but with your own code and there is suggested code above. Feel free to re-open if the above answer does not solve your issue.

avatar joomdonation joomdonation - change - 22 Aug 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-08-22 11:39:55
Closed_By joomdonation
Labels Added: No Code Attached Yet
Removed: ?
avatar joomdonation joomdonation - close - 22 Aug 2021

Add a Comment

Login with GitHub to post a comment