Welcome, Guest
Username: Password: Remember me

TOPIC: Custom SAVE in a model

Custom SAVE in a model 10 Apr 2015 15:59 #12909

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
I have to hold up my hand.. I have not got a clue how saving works now in Joomla 3.2 onwards..

The models have SELECT queries galore and I have no problems modifying those, but how on earth does SAVING work these days.. I am assuming this is all taken control of by a Joomla 3 library now that JCOOK uses as I have search every single file, the plugin and not one single insert or update SQL query to be found.

My issues is this

I have a security table in my component called feeds.

When ever someone updates another table (not all just a select few) I want to send a record to the feeds tabled.

Example

Someone creates an entry in 'places' then I want to send a record with values

(place.id, 'Has created a place', date, jomlauser.id)

same with updates

So I need to update the SAVE task for place so that when a new entry is created and new entry is ALSO created in the feed model.

I understand the adding with be slightly more complex, as the last record created will also need to be called, but if someone can get me started with an UPDATE of an existing place, how would that add a new RECORD to the feed table

Thanks
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Custom SAVE in a model 13 Apr 2015 16:49 #12910

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
Hi Morgan
Just a thought but Could you simply create a new model context, call it from the relevant controller for your view in the public Add function or define a custom function

Digging a little further by searching the downloaded component folder for "add" it does look like controllers\myview.php is calling a parent add function but i have not yet traced it back yet
Line 69: 	* Method to add an element.
	Line 74: 	public function add()
	Line 77: 		$this->_result = $result = parent::add();
	Line 83: 			case 'default.add':
	Line 92: 			case 'modal.add':

Also found this in classes\model\item.php...
/**
	* Concat SQL parts in query. (Suggested by Cook Self Service)
	*
	* @access	public
	* @param	string	$type	SQL command.
	* @param	string	$queryElement	Command content.
	* @return	void
	*/
	public function addQuery($type, $queryElement)
	{
		$queries = $this->getState('query.' . $type, array());
		if (!in_array($queryElement, $queries))
		{
			$queries[] = $queryElement;
			$this->setState('query.' . $type, $queries);
		}
	}

Sorry not much help as of yet but keen to know the answer as well
The administrator has disabled public write access.

Custom SAVE in a model 13 May 2015 12:52 #12980

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Lets assume your other table is called "otheritems"

Fork the controller "otheritem" (create a "fork" folder in the admin part and a subfolder "controllers", copy and paste "otheritem" from the _fork/controllers folder)
Open the "otheritem" controller from the generate code, copy and paste the public function save from it in your forked controller.

In the top of the function there will probably something like:
$result = parent::save();
You can do a check if the result was a succes and then add code to save an entry in your feed table.
If you do not know how to do that, then I can provide futher example code :)
The administrator has disabled public write access.
Time to create page: 0.102 seconds

Get Started