Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
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

Please Log in or Create an account to join the conversation.

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

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.055 seconds

I would like to Thank you for the Speed and the Quality of your work.
Pantelis (Forum)

Get Started