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

More
6 years 7 months ago - 6 years 7 months ago #72484 by Ali_wdm
I want to create flexicontent item with specified type and specified title.

I have written this code to create item
Code:
$log_filename = 'item_creation_'.($user->id).'.php'; jimport('joomla.log.log'); JLog::addLogger(array('text_file' => $log_filename)); // ************************************** // 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'); // **************************** // Create the item model object // **************************** require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'item.php'); $item_model = new FlexicontentModelItem(); // Create the new item data $data = array(); $data['type_id'] = $typeId; $data['title'] = $itemTitle; if ( !$item_model->store($data) ) { $msg = 'Failed to store item: '. $item_model->getError(); JLog::add($msg); $obj->result = "error"; $obj->msg = $msg; }

I am getting this error.

Call to undefined method stdClass::reset()





Also I want to delete flexicontent item by itemId in custom code, what should I do for this...??
Last edit: 6 years 7 months ago by ggppdk.

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

More
6 years 7 months ago - 6 years 7 months ago #72486 by Ali_wdm
$item_model = new FlexicontentModelItem();
When I print $item_model, I get this.
Code:
FlexicontentModelItem Object ( [record_name] => item [records_dbtbl] => content [records_jtable] => flexicontent_items [_id] => [_record] => [events_context] => com_content.article [useLastOrdering] => [plugins_group] => content [extension_proxy] => [associations_context] => com_content.item [_cparams] => Joomla\Registry\Registry Object ( [data:protected] => stdClass Object ( [flexi_cat_extension] => com_content [add_search_prefix] => 0 [filter_word_like_any] => 0 [flexi_fish] => 0 [editjf_translations] => 0 [use_mobile_layouts] => 1 [force_desktop_layout] => 1 [debug_mobile] => 0 [login_page] => index.php [add_item_sef_segment] => 1 [default_menu_itemid] => 537 [default_menuitem_preference] => 2 [default_menuitem_nopathway] => 1 [automatic_pathways] => 0 [add_canonical] => 1 [print_behaviour] => auto [show_print_icon] => 1 [show_email_icon] => 1 [show_feed_icon] => 1 [show_feed_link] => 1 [show_csvbutton] => 0 [show_editbutton] => 1 [show_deletebutton] => 1 [show_state_icon] => 1 [show_icons] => 2 [use_font_icons] => 1 [font_icon_classes] => pdf:icon-book, print:icon-print, mail:icon-envelope, feed:icon-feed, edit:icon-pencil, new:icon-new, approval:icon-key [btn_grp_dropdown] => 0 [btn_grp_dropdown_class] => icon-options [show_title] => 1 [link_titles] => 1 [show_intro] => 1 [comments] => 0 [comments_admin_link] => index.php?option=com_comment [hits_count_unique] => 1 [hits_mins_to_unique] => 600 [hits_skip_ips] => 1 [hits_ips_list] => 127.0.0.12 [hits_skip_bots] => 1 [hits_bots_list] => bot,spider,crawler,search,libwww,archive,slurp,teoma [tags_using_catview] => 0 [favs_using_catview] => 0 [cat_orderby] => order [catlimit] => 100 [inheritcid] => -1 [debug_inheritcid] => 0 [show_addbutton] => 1 [addbutton_menu_itemid] => 515 [show_cat_title] => 1 [title_cut_text] => 200 [show_description_image] => 0 [cat_image_source] => 2 [cat_link_image] => 1 [cat_image_method] => 1 [cat_image_width] => 80 [cat_image_height] => 80 [show_description] => 1 [trigger_onprepare_content_cat] => 0 [show_subcategories] => 0 [subcat_orderby] => order [show_itemcount] => 1 [show_subcatcount] => 0 [show_empty_cats] => 1 [show_description_image_subcat] => 0 [subcat_image_source] => 2 [subcat_link_image] => 1 [subcat_image_method] => 1 [subcat_image_width] => 24 [subcat_image_height] => 24 [show_description_subcat] => 0 [description_cut_text_subcat] => 120 [show_label_subcats] => 1 [subcat_separatorf] => 0 [show_peercategories] => 1 [peercat_orderby] => order [show_itemcount_peercat] => 0 [show_subcatcount_peercat] => 0 [show_empty_peercats] => 1 [show_description_image_peercat] => 0 [peercat_image_source] => 2 [peercat_link_image] => 1 [peercat_image_method] => 1 [peercat_image_width] => 24 [peercat_image_height] => 24 [show_description_peercat] => 0 [description_cut_text_peercat] => 120 [show_label_peercats] => 1 [peercat_separatorf] => 0 [ff_placement] => 0 [ff_toggle_search_title] => FLEXI_TOGGLE_SEARCH_FORM [filter_autosubmit] => 0 [filter_instructions] => 1 [show_search_go] => 0 [flexi_button_class_go] => btn btn-success [show_search_reset] => 1 [flexi_button_class_reset] => btn [filter_placement] => 1 [filter_separatorf] => 0 [use_search] => 0 [show_search_label] => 1 [search_autocomplete] => 1 [show_searchphrase] => 0 [default_searchphrase] => all [use_filters] => 0 [filters_order] => 1 [show_filter_labels] => 1 [use_persistent_filters] => 0 [show_alpha] => 0 [alphaskipempty] => 0 [clayout] => depoint [less_folders] => JPATH_COMPONENT_SITE/assets/less/ :: JTEMPLATE_SITE/less/com_flexicontent/ :: [clayout_switcher] => 0 [clayout_switcher_display_mode] => 1 [clayout_switcher_label] => 0 [displayed_clayouts] => Array ( [0] => depoint [1] => depoint-list ) [show_editbutton_lists] => 1 [show_state_icon_lists] => 1 [show_deletebutton_lists] => 1 [show_comments_count] => 1 [show_title_lists] => 1 [link_titles_lists] => 1 [force_full] => 0 [show_readmore] => -1 [non_orderable_types] => account_via_submit,authoritems,toolbar,file,image,groupmarker,fcpagenav,minigallery,weblink,extendedweblink,email,fcloadmodule [orderby] => rdate [orderbycustomfield] => 1 [orderbycustomfieldid] => 0 [orderbycustomfielddir] => ASC [orderbycustomfieldint] => 0 [orderby_2nd] => modified [orderbycustomfield_2nd] => 1 [orderbycustomfieldid_2nd] => 0 [orderbycustomfielddir_2nd] => ASC [orderbycustomfieldint_2nd] => 0 [orderby_override] => 1 [orderby_override_2nd] => 0 [limit_options] => 20,30,50,200,500 [orderby_options] => Array ( [0] => _preconfigured_ [1] => date [2] => rdate [3] => modified [4] => __SAVED__ ) [orderby_options_2nd] => Array ( [0] => _preconfigured_ [1] => date [2] => rdate [3] => modified [4] => published [5] => alpha [6] => ralpha [7] => author [8] => rauthor [9] => hits [10] => rhits [11] => id [12] => rid [13] => commented [14] => rated [15] => order [16] => __SAVED__ ) [show_noauth] => 0 [display_subcategories_items] => 0 [filtercat] => 1 [use_limit_before_search_filt] => 0 [limit_before_search_filt] => 0 [display_flag_featured] => 1 [limit] => 10 [show_item_total] => 1 [show_pagination] => 2 [show_pagination_results] => 1 [limit_override] => 0 [limit_override_label] => 2 [mu_addcss_cats] => Array ( [0] => featured [1] => __SAVED__ ) [mu_addtext_cats] => 1 [mu_addcss_acclvl] => Array ( [0] => needed_acc [1] => obtained_acc [2] => __SAVED__ ) [mu_add_condition_obtainded_acc] => 0 [mu_addtext_acclvl] => Array ( [0] => no_acc [1] => free_acc [2] => needed_acc [3] => obtained_acc [4] => __SAVED__ ) [mu_no_acc_text] => FLEXI_MU_NO_ACC [mu_free_acc_text] => FLEXI_MU_FREE [mu_addcss_radded] => 0 [mu_addtext_radded] => 1 [mu_ra_timeframe_intervals] => 24h , 2d , 7d , 1m , 3m , 1y , 3y [mu_ra_timeframe_names] => FLEXI_24H_RA , FLEXI_2D_RA , FLEXI_7D_RA , FLEXI_1M_RA , FLEXI_3M_RA , FLEXI_1Y_RA , FLEXI_3Y_RA [mu_addcss_rupdated] => 0 [mu_addtext_rupdated] => 1 [mu_ru_timeframe_intervals] => 24h , 2d , 7d , 1m , 3m , 1y , 3y [mu_ru_timeframe_names] => FLEXI_24H_RU , FLEXI_2D_RU , FLEXI_7D_RU , FLEXI_1M_RU , FLEXI_3M_RU , FLEXI_1Y_RU , FLEXI_3Y_RU [feed_limit] => 10 [feed_summary] => 0 [feed_summary_cut] => 200 [feed_show_readmore] => 0 [feed_use_image] => 1 [feed_link_image] => 1 [feed_image_width] => 80 [feed_image_height] => 80 [feed_image_method] => 1 [feed_orderby] => rdate [feed_orderbycustomfield] => 0 [feed_orderbycustomfieldid] => 0 [feed_orderbycustomfielddir] => ASC [feed_orderbycustomfieldint] => 0 [feed_orderby_2nd] => alpha [feed_orderbycustomfield_2nd] => 1 [feed_orderbycustomfieldid_2nd] => 0 [feed_orderbycustomfielddir_2nd] => ASC [feed_orderbycustomfieldint_2nd] => 0 [cat_myitems_default_menu_itemid] => 280 [cat_mcats_default_menu_itemid] => 265 [filtertag] => 1 [favs_view_default_menu_itemid] => 367 [search_view_default_menu_itemid] => 498 [use_joomla_featured_flag] => 1 [featured_cats_parent_disable] => 1 [allowbuttons_fe] => Array ( [0] => apply [1] => save_preview [2] => __SAVED__ ) [buttons_placement_fe] => 0 [approval_warning_inform_fe] => 0 [approval_warning_aftersubmit_fe] => 1 [notauthurl] => 515 [use_captcha] => 1 [captcha_formop] => 1 [usetitle_fe] => 0 [usealias_fe] => 0 [usetags_fe] => 1 [allowdisablingcomments_fe] => 0 [uselang_fe] => 0 [default_language_fe] => * [langdisplay_fe] => 2 [langdisplay_flags_fe] => 1 [langdisplay_texts_fe] => 1 [allowlangmods_fe] => Array ( [0] => mod_item_lang [1] => __SAVED__ ) [allow_subscribers_notify_fe] => 0 [usepublicationdetails_fe] => 0 [usemetadata_fe] => 0 [useseoconf_fe] => 0 [usedisplaydetails_fe] => 0 [selecttheme_fe] => 0 [form_tab_titles] => 1:FLEXI_DESCRIPTION, 2:__TYPE_NAME__, 3:FLEXI_ASSIGNMENTS, 4:FLEXI_PUBLISHING, 5:FLEXI_META_SEO, 6:FLEXI_DISPLAYING, 7:FLEXI_TEMPLATE [form_tab_icons] => 1:icon-file-2, 2:icon-signup, 3:icon-tree-2, 4:icon-calendar, 5:icon-bookmark, 6:icon-eye-open, 7:icon-palette [form_tabs_above] => title, alias, category, lang, type, state, disable_comments, notify_subscribers [form_tabs_below] => fields_manager , text , access [form_tab01_fields] => _skip_ [form_tab02_fields] => _skip_ [form_tab03_fields] => _skip_ [form_tab04_fields] => _skip_ [form_tab05_fields] => _skip_ [form_tab06_fields] => _skip_ [form_tab07_fields] => _skip_ [form_font_icons] => 1 [new_item_state] => 1 [new_item_state_fe] => 1 [non_publishers_item_state] => -4 [non_publishers_item_state_fe] => -4 [use_versioning] => 0 [disable_diff] => 0 [nr_versions] => 10 [versionsperpage] => 5 [auto_approve] => 1 [enable_notifications] => 0 [nf_allow_cat_specific] => 1 [nf_send_as_bcc] => 1 [nf_extra_properties] => Array ( [0] => creator [1] => modifier [2] => created [3] => modified [4] => viewlink [5] => editlinkfe [6] => editlinkbe [7] => __SAVED__ ) [nf_add_introtext] => 0 [nf_add_fulltext] => 0 [nf_enable_debug] => 0 [states_notify_new] => Array ( [0] => 1 [1] => 0 [2] => __SAVED__ ) [states_notify_existing] => Array ( [0] => 1 [1] => 0 [2] => 2 [3] => -3 [4] => -4 [5] => -5 [6] => __SAVED__ ) [show_updatecheck] => 1 [dashboard_buttons_hide] => Array ( [0] => __SAVED__ ) [dashboard_sliders_disable] => Array ( [0] => pending [1] => revised [2] => inprogress [3] => __SAVED__ ) [dashboard_modal_item_edit] => 1 [dashboard_disable_fc_logo] => 0 [dashboard_hide_fc_license_credits] => 1 [iman_viewable_items] => 1 [iman_editable_items] => 0 [copytask_allow_uneditable] => 1 [items_session_editable] => 0 [autoflogin] => 1 [show_csvbutton_be] => 0 [items_manager_order] => i.id [items_manager_order_dir] => DESC [import_lang] => * [import_state] => 1 [import_access] => 1 [import_created_by_col] => 0 [import_modified_by_col] => 0 [import_metadesc_col] => 0 [import_metakey_col] => 0 [import_created_col] => 0 [import_modified_col] => 0 [import_publish_up_col] => 0 [import_publish_down_col] => 0 [import_tags_col] => 0 [import_media_folder] => tmp/fcimport_media [import_docs_folder] => tmp/fcimport_docs [csv_field_sep] => ~~ [csv_item_record_sep] => \n~~ [csv_debug_records] => 0 [csv_field_mval_sep] => %% [csv_field_mprop_sep] => !! [import_ignore_unused_cols] => 0 [import_id_col] => 0 [import_items_per_step] => 5 [display_file_lang_as] => 1 [file_path] => components/com_flexicontent/uploads [media_path] => components/com_flexicontent/medias [index_pdf_files] => 0 [upload_maxsize] => 10000000 [upload_extensions] => bmp,csv,doc,docx,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,pptx,swf,txt,xcf,xls,xlsx,zip,ics,mp4 [resize_on_upload] => 1 [upload_max_w] => 4000 [upload_max_h] => 3000 [upload_method] => 0 [restrict_uploads] => 1 [image_extensions] => bmp,gif,jpg,png [upload_mime_illegal] => text/html [upload_mime] => image/jpeg,image/gif,image/png,image/bmp,application/x-shockwave-flash,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip [disablecss] => 1 [add_tooltips] => 0 [loadfw_jquery] => 1 [loadfw_image_picker] => 2 [loadfw_masonry] => 2 [loadfw_select2] => 2 [loadfw_inputmask] => 2 [loadfw_prettycheckable] => 0 [loadfw_fancybox] => 2 [loadfw_bootstrap_css] => 2 [always_create_fields_display] => 0 [advcache] => 1 [advcache_time] => 252000 [recompile_core_less] => 0 [print_logging_info] => 0 [show_usability_messages] => 1 [debug_initial_perms] => 0 [title_display_label] => 1 [auto_title] => 0 [auto_title_code] => $F = & $item->fields; $txt = isset( $F['fieldname01'] ) ? $F['fieldname01']->postdata[0] : 'fieldname01 field not found'; return $txt; [maintext_display_label] => 1 [hide_maintext] => 0 [maintext_height] => 400 [voting_display_label] => 1 [voting_main_counter] => 1 [voting_main_counter_show_percentage] => 1 [favourites_display_label] => 1 [catid_allowed_parent] => 17 [catid_allowed_parent_disable] => 0 [catid_default] => 18 [cid_allowed_parent] => 18 [cid_allowed_parent_disable] => 0 [override_title] => 0 [addcat_title] => 1 [type_menu_itemid] => 515 [type_menu_itemid_usage] => 0 [allow_jview] => 0 [search_jlinks] => 1 [jview_fields_placement] => 1 [ilayout] => depoint ) [initialized:protected] => 1 [separator] => . ) [_cid] => 0 [_ilayout] => [_typeid] => 14 [_version] => [_translations] => [record_keys] => Array ( [0] => id ) [_messages] => Array ( ) [text_prefix:protected] => COM_FLEXICONTENT [event_after_delete:protected] => onContentAfterDelete [event_after_save:protected] => onContentAfterSave [event_before_delete:protected] => onContentBeforeDelete [event_before_save:protected] => onContentBeforeSave [event_change_state:protected] => onContentChangeState [batch_copymove:protected] => category_id [batch_commands:protected] => Array ( [assetgroup_id] => batchAccess [language_id] => batchLanguage [tag] => batchTag ) [associationsContext:protected] => [batchSet:protected] => [user:protected] => [table:protected] => [tableClassName:protected] => [contentType:protected] => [type:protected] => [tagsObserver:protected] => [_forms:protected] => Array ( ) [events_map:protected] => Array ( [delete] => content [save] => content [change_state] => content [validate] => content ) [__state_set:protected] => [_db:protected] => JDatabaseDriverMysqli Object ( [name] => mysqli [serverType] => mysql [connection:protected] => mysqli Object ( [affected_rows] => 1 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 2 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.5-10.1.25-MariaDB [server_version] => 50505 [stat] => Uptime: 5725 Threads: 1 Questions: 18406 Slow queries: 0 Opens: 230 Flush tables: 1 Open tables: 217 Queries per second avg: 3.215 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 147 [warning_count] => 0 ) [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [_database:JDatabaseDriver:private] => dev2 [count:protected] => 20 [cursor:protected] => [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [timings:protected] => Array ( ) [callStacks:protected] => Array ( ) [offset:protected] => 0 [options:protected] => Array ( [driver] => mysqli [host] => localhost [user] => root [password] => [database] => dev2 [prefix] => app_ [select] => 1 [port] => 3306 [socket] => ) [sql:protected] => SELECT t.id, t.attribs FROM #__flexicontent_types AS t WHERE t.id = 14 [tablePrefix:protected] => app_ [utf:protected] => 1 [utf8mb4:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [transactionDepth:protected] => 0 [disconnectHandlers:protected] => Array ( ) ) [name:protected] => item [option:protected] => com_flexicontent [state:protected] => Joomla\CMS\Object\CMSObject Object ( [_errors:protected] => Array ( ) ) [event_clean_cache:protected] => onContentCleanCache [_errors:protected] => Array ( ) )


I think, Flexi content Model is not loaded properly.
Last edit: 6 years 7 months ago by ggppdk.

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

More
6 years 7 months ago #72489 by ggppdk
Hello

are you using FC v3.2.1.12 ?


-- 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 7 months ago #72490 by Ali_wdm
Yes, I am using latest version of flexicontent (FC v3.2.1.12).

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

More
6 years 7 months ago #72491 by ggppdk
Hello

start by using the exact copy of this code:
flexicontent.org/documentation/faq/70-de...-in-custom-code.html

and then customize

notice that
- i have added error_reporting() printing in it (you can remove it when done)
- and also
Code:
$itemID = 0; // 444
to create new item


-- 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 7 months ago #72492 by Ali_wdm

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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.383 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