Welcome, Guest
Username: Password: Remember me

TOPIC: Detecting if new or updated in save function

Detecting if new or updated in save function 14 Jun 2015 16:27 #13262

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
I have writen some custom code in a save model which I need to be able to detect if a record is being created or updated

I thought I could do this by detecting if ID was specified as a new record would not have an ID, but this was not correct.. here is the sniippet of code. How can I alter it to detect NEW or UPDATED record

Here is the code... in ALL instances wether creating a new record or updating it, $data[ID] is always true
if (parent::save($data)) {

    if (isset($data['id'])) {
        // do this
    } else {
        // do that
    }
    return true;
}
Morgan Leecy MCSE

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

Detecting if new or updated in save function 14 Jun 2015 16:50 #13263

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
Dammit... that was easy.. I just made a slight alteration

Instead of using
if (isset($data['id']))

ust alter it to
if ($data['id']) {

This works..

who would have thought...
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.
Time to create page: 0.122 seconds

Get Started