[SOLVED] update item with custom field

5 years 2 months ago - 5 years 2 months ago #64773 by fopo-web
Hi, I read in an own plugin a flexicontent item. f.e.:
$itemmodel_name = FLEXI_J16GE ? 'FlexicontentModelItem' : 'FlexicontentModelItems';
$itemmodel = new $itemmodel_name();
$item = $itemmodel->getItem($id, $check_view_access=true);
$items = array(&$item);
FlexicontentFields::getFields($items);
FlexicontentFields::getFieldDisplay($item, 'myfield');
$value = $item->fields['myfield']->display;

How can I modify the value of "myfield" and how can I save the item after this?


regards,

Frank

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

5 years 2 months ago - 5 years 2 months ago #64774 by ggppdk
Hello

that code you mentioned is for viewing / display item data in item code

Please read this for creating new or changing existing items:
How to create a new FLEXIcontent item or edit an existing item by calling the FLEXIcontent item model in custom code
www.flexicontent.org/documentation/faq/7...-in-custom-code.html


If you have create a new field type then use
onBeforeSaveField() for saving data when saving FLEXIcontent item form:
How to Duplicate a Flexicontent Field to create a new Field Type
www.flexicontent.org/documentation/faq/7...-new-field-type.html


-- 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 review. Thanks!

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

5 years 2 months ago #64784 by fopo-web
Hi, thanks for your fast answer. I have try it, but I get following error:
<br />
<b>Fatal error</b>:  Call to undefined method FlexicontentModelItem::_loadItemParams() in
<b>.../administrator/components/com_flexicontent/models/parentclassitem.php</b> on line
<b>322</b>
<br />

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

5 years 2 months ago #64785 by ggppdk
Hello

are you running this from inside Joomla or from custom script ?

are in Joomla Frontend or backend ?

what is the current component of your currently view page (/URL) ?


-- 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 review. Thanks!

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

5 years 2 months ago #64792 by fopo-web
Hi,

I have written a Joomla Plugin for der Joomla Rest Extension. I want to show and modify items in a android app. The reading of my items works (GET), but If I want modify an item I will get the error above.

My code:
<?php
 
// No direct access.
defined('_JEXEC') or die;
 
jimport('joomla.application.component.model');
require_once (JPATH_ADMINISTRATOR.DS.'components/com_flexicontent/defineconstants.php');
 
require_once(JPATH_SITE.DS."components/com_flexicontent/classes/flexicontent.helper.php");
require_once(JPATH_SITE.DS."components/com_flexicontent/classes/flexicontent.categories.php");
require_once(JPATH_SITE.DS."components/com_flexicontent/classes/flexicontent.fields.php");
require_once(JPATH_SITE.DS."components/com_flexicontent/classes/flexicontent.acl.php");
require_once(JPATH_SITE.DS."components/com_flexicontent/helpers/permission.php");
require_once(JPATH_SITE.DS."components/com_flexicontent/helpers/route.php");
require_once(JPATH_SITE.DS."components/com_content/helpers/route.php");
 
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'tables');
 
 
class SnowfunApiResourceTest extends ApiResource
{
    public function get() {
		...
	}
 
    public function post()
    {
		$app = JFactory::getApplication();
		$tmp = $app->input->get('param', '', 'STRING');
 
		$area = json_decode($tmp);		
 
		require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php');
		$itemmodel = new FlexicontentModelItem();
		$item = $itemmodel->getItem($area->id);
 
		$item['custom']['myfield'] = $area->fieldValue;
		$itemmodel->store($item);
 
        $this->plugin->setResponse( $item );
    }
}

I have no idea.

regards,

Frank

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

5 years 2 months ago #64805 by fopo-web

ggppdk wrote: Please read this for creating new or changing existing items:
How to create a new FLEXIcontent item or edit an existing item by calling the FLEXIcontent item model in custom code
www.flexicontent.org/documentation/faq/7...-in-custom-code.html


Is it possible that this documention not work for existing items? There is no method "load" in FlexicontentModelItem. I can use getItem, but I get an error on store the item, because the item is an object and not an array.

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

5 years 2 months ago - 5 years 2 months ago #64806 by ggppdk
Hello

aaah yes,
FlexicontentModelItem
inherits the method:

getItem() and not the load()

so you need to use getItem()

e.g.
$item_ID = 444;
$itemmodel->getItem($item_ID, $check_view_access=false, $no_cache=true, $force_version=0);

The parent class and the method are these:
github.com/FLEXIcontent/flexicontent-cck...ntclassitem.php#L298


- i ll make tests and update the FAQ artilce tomorrow late evening (UTC+2),


-- 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 review. Thanks!

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

5 years 2 months ago #64807 by fopo-web
Sorry, it does not work: :(

My code:
$itemmodel = new FlexicontentModelItem();		
$item = $itemmodel->getItem(368);

I get the error like in my first post:
<br />
<b>Fatal error</b>:  Call to undefined method FlexicontentModelItem::_loadItemParams() in
<b>/usr/www/users/fopozw/snowfun/snowfun/administrator/components/com_flexicontent/models/parentclassitem.php</b> on line
<b>322</b>
<br />

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

5 years 2 months ago #64808 by ggppdk
Hello

The parent class of the ITEM model,
- thinks that you are in Joomla frontend

so it tries to use:
_loadItemParams()

- which only exist in FlexicontentModelItem of frontend ,

Solution:

instead of:
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php');

do
require_once(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php');


thus you will load the frontend model


-- 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 review. Thanks!

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

5 years 2 months ago #64809 by fopo-web
:(

The load of the item now works, but I can not save.
require_once(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php');
$itemmodel = new FlexicontentModelItem();
 
$item = $itemmodel->getItem($area->id);
$itemmodel->store($item);		

Error:
<br />
<b>Fatal error</b>:  Cannot use object of type stdClass as array in
<b>/usr/www/users/fopozw/snowfun/snowfun/administrator/components/com_flexicontent/models/parentclassitem.php</b> on line
<b>1688</b>
<br />

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

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.
Save
Cookies user prefences
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