Advertisement
Using the Joomla (not WEB Services) API.
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.
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.
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Using the Joomla (not WEB Services) API.
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?
$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
-
- Joomla! Champion
- Posts: 6452
- Joined: Tue Aug 23, 2005 1:56 pm
- Location: South coast, UK
- Contact:
Re: Using the Joomla (not WEB Services) API.
Paucity
https://gadsolutions.biz Electrical services
https://electrical-testing-safety.co.uk Testing services
https://electrical-testing-safety.co.uk Testing services
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Re: Using the Joomla (not WEB Services) API.
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.
-
- Joomla! Virtuoso
- Posts: 3100
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Using the Joomla (not WEB Services) API.
Use the backend model:
Code: Select all
$model = $factory->createModel('Article', 'Administrator');
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Re: Using the Joomla (not WEB Services) API.
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??
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??
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Re: Using the Joomla (not WEB Services) API.
Do I need to add some kind of authentication for this to work?
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Re: Using the Joomla (not WEB Services) API.
Was that a bad question
-
- Joomla! Enthusiast
- Posts: 151
- Joined: Tue Feb 28, 2006 3:23 pm
Re: Using the Joomla (not WEB Services) API.
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 ... )
- Per Yngve Berg
- Joomla! Master
- Posts: 31390
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
Re: Using the Joomla (not WEB Services) API.
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