Welcome, Guest
Username: Password: Remember me

TOPIC: Save an array of values in foreign table

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

  • andypooz
  • andypooz's Avatar
  • Offline
  • New Member
  • Posts: 18
  • Thank you received: 2
  • Karma: 0
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
The administrator has disabled public write access.

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

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
+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!!!
The administrator has disabled public write access.
Time to create page: 0.067 seconds

Get Started