Getting error on creating item by calling FLEXIcontent item model in custom code

More
6 years 1 month ago #72504 by Ali_wdm
Can you please give an example how to instatiate a FLEXIcontent controller instance, then set data into $POST, Then call remove() function...??

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72517 by Ali_wdm
Please reply, I am waiting for your response

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72518 by ggppdk
Hello

a little busy now

will try to give the code during today evening
otherwise tomorrow


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72519 by ggppdk
Hello

please don't hesitate to post a reminder tomorrow (or in a forum topic) if you do not get answer


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72520 by Ali_wdm
Ok thanks.
Please try to give code by today evening.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #72521 by ggppdk
Hello

without testing it here is the code
please test and correct any mistakes in the code below

First you should include the files that our FAQ article says as before for creating items
then try 2 cases:


CASE 1
use the items controller (this forces ACL check)

[EDIT]
i have removed this case from this answer as it is inflexible


CASE 2
use the items and item DB models (ACL optionally checked)

Code:
<?php // Get Joomla! framework define( '_JEXEC', 1 ); define( '_VALID_MOS', 1 ); define( 'JPATH_BASE', realpath(dirname(__FILE__)) ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $app = JFactory::getApplication('site'); $app->initialise(); global $globalcats; if (empty($globalcats)) { JPluginHelper::importPlugin('system', 'flexisystem'); // add the category tree to categories cache $catscache = JFactory::getCache('com_flexicontent_cats'); $catscache->setCaching(1); //force cache $catscache->setLifeTime(84600); //set expiry to one day $globalcats = $catscache->get( array('plgSystemFlexisystem', 'getCategoriesTree'), array() ); //$globalcats = plgSystemFlexisystem::getCategoriesTree(); } // Define component paths IF FLEXIcontent v3.1.0 or older // You do not need them for v3.1.1 or later !! define( 'JPATH_COMPONENT_SITE', JPATH_SITE.DS.'components'.DS.'com_flexicontent' ); define( 'JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent' ); // Create a log file $user = JFactory::getUser(); $log_filename = 'item_creation_'.($user->id).'.php'; jimport('joomla.log.log'); JLog::addLogger(array('text_file' => $log_filename)); error_reporting(E_ALL & ~E_STRICT); ini_set('display_errors',1); // ************************************** // Include the needed classes and helpers // ************************************** if (!defined('DS')) define('DS',DIRECTORY_SEPARATOR); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.helper.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.categories.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.fields.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.acl.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'permission.php'); require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'route.php'); // Add component's table directory to the include path JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'); // ******************* // Load language files // ******************* // (BACKEND) Load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true); // (BACKEND) Load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true); // (FRONTEND) Load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_SITE, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_SITE, null, true); // (FRONTEND) Load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_SITE, null, true); // Set item to delete, YOU DECIDE IF YOU CHECKING ACL IS NEEDED $id = 4444444; JLoader::register('FlexicontentModelItems', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'items.php'); JLoader::register('FlexicontentModelItem', JPATH_BASE.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php'); $model = new FlexicontentModelItems(); $itemmodel = new FlexicontentModelItem(); $app = JFactory::getApplication(); $db = JFactory::getDbo(); $user = JFactory::getUser(); // Get owner and other item data $q = 'SELECT id, created_by, catid FROM #__content WHERE id = ' . (int) $id; $itemdata = $db->setQuery($q)->loadObjectList('id'); if (!$itemdata) { die('Item ' . $id . ' not found'); } // Check authorization for delete operation $isOwner = $itemdata[$id]->created_by == $user->id; $asset = 'com_content.article.' . $id; $canDelete = $user->authorise('core.delete', $asset) || ($user->authorise('core.delete.own', $asset) && $isOwner); // CHECK or not check if user is allowed to delete if (1 || $canDelete) { // Try to delete if ($model->delete(array($id), $itemmodel)) { echo 'delete success'; } // Try to delete else { echo 'delete failed'; } } else { echo 'No access to delete failed'; }

please test and correct any mistakes in the above code


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 6 years 1 month ago by ggppdk.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.304 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline