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

TOPIC:

Save an array of values in foreign table 28 Mar 2012 17:10 #1765

I need to save a series of values into a table and need help changing the database class
function save($data)
	{

		$row = $this->getTable();



		//Convert data from a stdClass
		if (get_class($data) == 'stdClass')
			$data = JArrayHelper::fromObject($data);

		//Current id if unspecified
		if ($data['id'] != null)
			$id = $data['id'];
		else if (($this->_id != null) && ($this->_id > 0))
			$id = $this->_id;


		//Load the current object, in order to process an update
		if (isset($id))
			$row->load($id);


		// Bind the form fields to the lockr table
		$ignore = array();
		if (!$row->bind($data, $ignore)) {
			JError::raiseWarning(1000, $this->_db->getErrorMsg());
			return false;
		}





		// Make sure the lockr table is valid
		if (!$row->check()) {
			JError::raiseWarning(1000, $this->_db->getErrorMsg());
			return false;
		}



		// Store the lockr table to the database
		if (!$row->store())
        {
			JError::raiseWarning(1000, $this->_db->getErrorMsg());
			return false;
		}



		$this->_id = $row->id;
		$this->_data = $row;



		return true;
	}


The field name is notes[], and I have javascript adding extra fields on the form (so the array could be 1 or 20+)
The database table that these values need to be saved to is #__lockr_drillnotes (which is not the main #__lockr_drills table that this save routine saves the rest of the data to)

I know that this needs to happen after the main save routine happens because I need to use the id from the other table as a foreign key to link the note to this drill.

Any ideas? If explaining this will take more time than you can spare, I am happy to pay for someone to customise this code.

Thank you all
Andy

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

Re: Save an array of values in foreign table 18 Sep 2012 15:23 #3744

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
+1

I'm trying to achieve the same thing with collections/albums of related audio & video whereby in the album form, I need to be able to add multiple 'child' media items that will be saved as part of the same routine.

Would the best way to go be to save the array of child items (if any) by calling a function in the controller or model of the child table?

Any advice or example on how best to achieve this would be greatly appreciated!

Many thanks,

Gez

P.S. Is this something that will be or indeed is already part of version 2?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

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

  • Page:
  • 1
Time to create page: 0.053 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started