Advertisement

Using the Joomla (not WEB Services) API.

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Using the Joomla (not WEB Services) API.

Post by davidascher » Fri Oct 25, 2024 2:24 pm

i'm trying to develop a module that I can use to write updated introtext to an (obviously) existing article. Is it necessary to create the app using
$app = Factory::getApplication('admin'); // or something like admin?
Instead of just
$app = Factory::getApplication();
Or is it enough to create the module as a Admin module?

There seems to be a paucity of documentation of a lot of the details about how to use this API as I can find only a few simple sample code examples but a LOT of documentation on the use of the Web Services API. Have I not found the treasure trove of documentation that exists somewhere out there for the Joomla API or is the idea that we should not use that API anymore now that the Webservices API has been unleashed?

Advertisement
gws
Joomla! Champion
Joomla! Champion
Posts: 6453
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Using the Joomla (not WEB Services) API.

Post by gws » Sat Oct 26, 2024 6:12 pm

:) Paucity

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Joomla (not WEB Services) API.

Post by davidascher » Sat Oct 26, 2024 8:28 pm

gws wrote: Sat Oct 26, 2024 6:12 pm:) Paucity
I guess I should have written "dearth" instead.

In any case, I have been able to retrieve an article using
$app = Factory::getApplication();
$factory = $app->bootComponent('com_content')->getMVCFactory();
$model = $factory->createModel('Article');
$article = $model->getItem($articleId);

at that point I have some code that modifies the introtext (never mind the details) in the $article object (array?) and I'm ready to write the updated introtext back. I tried using
$model->save($article);
but that causes an error:
0 Call to undefined method Joomla\Component\Content\Site\Model\ArticleModel::save()
I would guess that I need to add another "use" directive because the save function/method only exists in the administrator version of com_content. OR, perhaps, it is just not possible to use save() at all?

I'd be happy with know where I could find this info, but delighted if somebody could tell me how I should be doing this.

SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3102
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Using the Joomla (not WEB Services) API.

Post by SharkyKZ » Sat Oct 26, 2024 8:54 pm

Use the backend model:

Code: Select all

$model = $factory->createModel('Article', 'Administrator');

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Joomla (not WEB Services) API.

Post by davidascher » Mon Oct 28, 2024 1:00 am

I made that change and got the error
Cannot use object of type Joomla\CMS\Object\CMSObject as array

I changed the line to
$model->save(array($article));

And that error went away. However, the article that was supposed to have its introtext updated did not get updated and I saw no error indication. Is there some flag that needs to be set within the article object (or array) so the update can proceed??

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Joomla (not WEB Services) API.

Post by davidascher » Mon Oct 28, 2024 11:41 am

Do I need to add some kind of authentication for this to work?

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Joomla (not WEB Services) API.

Post by davidascher » Wed Oct 30, 2024 9:41 pm

Was that a bad question ❓

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Joomla (not WEB Services) API.

Post by davidascher » Fri Nov 01, 2024 12:44 pm

I seem to have missed something basic and critical for this to work. I have a number of guesses about what those things might be.
  • What I'm attempting to do must be done in a component and cannot be done in a module
  • What I'm attempting to do (write new content into an existing article) must be done only after proper credentials for the user are provided - either through the login module or hard coded (securely, of course) within the code
  • The article must first be checked out? Or somehow put into a state where it is "modifiable"
  • The article needs to be deleted and then recreated with the original articleId (this seems unlikely, but ... )
Does anybody have any hints or tips to offer?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 31395
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Using the Joomla (not WEB Services) API.

Post by Per Yngve Berg » Fri Nov 01, 2024 2:43 pm

I don't see the Picture of what you are trying to achieve, but I have the impression that is should have been done with a Plugin.

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”