Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

JSON object behaviour in populateObjects 16 Sep 2013 09:48 #11102

for some unknown reason to me, the code in the function populateObjects:
		if (!empty($item->my_json_object))
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_object);
			$item->my_json_object = new JObject($registry->toObject());
		}

return an empty object when I call directly the $model->getItem()

if I use the simple json_decode, it always perfectly works:
		if (!empty($item->my_json_object) AND is_string($item->my_json_object))
		{
			$item->my_json_object = json_decode($item->my_json_object);
		}

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

JSON object behaviour in populateObjects 23 Sep 2013 17:53 #11154

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed since 2.6
$item->my_json_object = new JObject($registry->toObject());

To:
$item->my_json_object = $registry->toObject();

Simple...
Coding is now a piece of cake
The following user(s) said Thank You: Tomaselli

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

JSON object behaviour in populateObjects 27 Sep 2013 11:24 #11198

Thanks for the fix.
I noticed a little bug when the function populateObjects is called again (for example when you call the function getForm).
In this situation the function populateObjects will overwrite the JSON object and the data will be deleted, to avoid that afurther check should be added:

Original jcook 2.6:
		if (!empty($item->my_json_obejct))
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_obejct);
			$item->my_json_obejct = $registry->toObject();
		}

Modified:
		if (!empty($item->my_json_obejct) AND is_string($item->my_json_obejct)) /* hack */
		{
			$registry = new JRegistry;
			$registry->loadString($item->my_json_obejct);
			$item->my_json_obejct = $registry->toObject();
		}
The following user(s) said Thank You: admin

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

JSON object behaviour in populateObjects 27 Sep 2013 11:28 #11199

I'm also thinking that function populateObejcts should be called just ONCE on the same Item (and it is called more than once), shouldn't be added a static variable to check that?

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

JSON object behaviour in populateObjects 07 Oct 2013 00:19 #11303

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed now.
Coding is now a piece of cake
The following user(s) said Thank You: Tomaselli

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

JSON object behaviour in populateObjects 08 Oct 2013 07:58 #11328

thank you

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

  • Page:
  • 1
Time to create page: 0.067 seconds
Great UX great performance and definitely a time saver. It only took me 10 minutes of playing around before purchasing a subscription and right now I just want to throw more money at you! I just started a new project and after just 4h I can already tell it probably saved me several days of work. I'm building a wholesale ordering system with sales rep management. I have not looked at the code yet but so far: impressive.
flip (Forum)

Get Started