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

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started