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.056 seconds

  I found "cook" two days ago. Played around with it for a day and then within a day got rid of two legacy applications in IBM Lotus Domino Notes and replaced them with "cook". It was really easy. A piece of cake. Actually it was even easier than cooking. Cooking involves more work than developing with "cook". What can I say about "cook"? Great application great price for what it delivers great forum with a lot of information and fast responses active and friendly community fast forward moving development cycle So what should I say "Monsieur Le Cook"? Keep the good work going it will lead to success. Having become a paying member in the words of Edith Piaf may I say ..... non rien de rien ... je ne regrette rien. Vive La France.
FK (JED)
         

Get Started