Can anyone explain structure of content and assets table. I m adding articles by API so how i can insert data into that two tables. In which table i have to add first. Please guide.
-
Thanks for your answer and i will implement it but how i can upload image or how i can specify image url. Can anyone guide?– Info TruthNov 24, 2016 at 15:09
-
I discovered your comment purely by chance. Don't expect others to be notified after commenting under your question. Please read the help center section of JSE to find out how the site works. Also read the small help section of the comments. Regarding your comment, this is not directly related with the title of your question, which is the Assets table. Consider asking another question - explaining clearly your current problem. Regarding this question - if the answers below answered it, then consider accepting it - joomla.stackexchange.com/help/someone-answers– FFrewinNov 25, 2016 at 6:00
1 Answer
1. Adding Joomla Content via the API
Not sure how you are using the API to create articles and why it doesn't create the assets entries for you - assuming you have already tried to do so - as, adding Joomla content through the API will handle this for you.
So you don't actually need to do anything extra in order to create the corresponding assets entries for your articles.
In short the procedure is:
1. Instatiate the JTableContent Object
$item = JTable::getInstance('Content');
2. Create your article's properties:
$item->title = $myTitle;
$item->alias = JFilterOutput::stringURLSafe($myAlias);
$item->introtext = $articleText;
//... and so on
3. Save the article:
$item->store();
2. The Assets Table
In brief the foreach article there should be a related assets record which will hold ACL information about the article.
The assets table follows the Nested Set Model to store data Hierhically, similar to how data are represented in XML
, where every item has a Parent Item and 0 or more Children - except of the Root Item that has no parent.
Read this answer on an old question related with issues with com_tags
in the assets table, where if I can recall right there is an example explanation of how left/righ/level values are calculated, with an example diagram: Unexpected parent tag association.
In that answer there is also a link to a great post that explains the Nested Set Model
Update
I just remembered there was some docs in Joomla.org about using nested set model, which can be found here: https://docs.joomla.org/Using_nested_sets
3. Docs
-
1Just tried your code and I confirm it works and creates the correct entries in the asset table. Thanks so much!!! Feb 8, 2021 at 19:24
-
I used this method and that got the assets table entry inserted correctly. I still had to insert the content and workflow_associations records myself, but the assets table was the hard part. Thanks for this! Oct 27, 2022 at 4:43