Create a Joomla! Article Programmatically
It's not possible to change the working directory because its a constant. To work around this issue you could choose not to use ContentModelArticle at all and instead use the table class only:
$table = JTable::getInstance('Content', 'JTable', array());
$data = array(
'catid' => 1,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
// Bind data
if (!$table->bind($data))
{
$this->setError($table->getError());
return false;
}
// Check the data.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// Store the data.
if (!$table->store())
{
$this->setError($table->getError());
return false;
}
Note that the code above does not trigger the before/after save events. If that is needed however, it should not be a problem to trigger those events. Also worth noticing is that the field published_up will not be automatically set and the articles within the category will not be reordered.To reorder the category:
$table->reorder('catid = '.(int) $table->catid.' AND state >= 0');
Programmatically add a Joomla Article from CLI
I was able to find the answer to this as it had been raised as an issue at github, so I am posting that solution here.
https://github.com/joomla/joomla-cms/issues/7028
It is necessary to register the application like this, if the command line app uses JTable:
class MakeSql extends JApplicationCli
{
public function __construct()
{
parent::__construct();
JFactory::$application = $this; // this is necessary if using JTable
}
public function doExecute()
{
$db = JFactory::getDbo();
// ... etc etc ...
I did this and it worked fine. Is there a way to create multiple articles in Joomla at one back-end page?
Check out OS Content by JoomlaShack:
https://extensions.joomla.org/extension/oscontent/
Video demo at https://demoextensions.joomlashack.com/oscontent
Programmatically Create Menu Item in Joomla
Try using JTableNested::setLocation($referenceId, $position = 'after'):
$table->setLocation($parent_id, 'last-child');
I also think that you need to rebuild the path:// Rebuild the tree path.
if (!$table->rebuildPath($table->id)) {
$this->setError($table->getError());
return false;
}
If it still doesn't work, try to find out what programmatically edit articles in Joomla
when you say edit articles programmatically, do you mean edit the content of an article, or how it is presented and what else loads with it?
the former will require you to edit the db contents.
the latter means you need to look into how joomla's templating system works, which is most likely what you need to do. piece of further advice: modules have the ability to define class/id per instance, which will be very helpful for writing your css.
Related Topics
PHP - Swiftmailer Using Starttls and Self Signed Certificates
How to Remove Text Between Tags in PHP
Add Some Attribute Values to Woocommerce Variable Product Title from Chosen Variation
How to Force Ssl in Codeigniter
.Htaccess Deny Access to Specific Files? More Than One
Checking If String Contains "Http://"
Difference Between $_Server['Document_Root'] and $_Server['Http_Host']
Finding First Day of Week via PHP
Xpath Get Attribute Value in PHP
Posting to a Facebook Page as the Page (Not a Person)
Force Download via Ajax and PHP
MySQL Int(11) Number Out of Range
Zend Framework 2 - Global Check for Authentication with Zfcuser
PHP Sum Variable in While Loop
Php/MySQL with Encoding Problems