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

Freakin' Awesome!!! J-Cook is simply awesome - whether you're a highly experienced developer or complete novice whether you're building a small inventory component or a complete community solution! The beauty comes from a fast slick and reliable platform that readily provides developers with everything they'll need to build the backbone of a solid and secure component with wizards for authoring access publishing aliasing created/modified by dates... you name it COOK provides it! J-Cook really surpasses all of the 'competition' as far as MVC tools are concerned! Try love it and get cooking!
learnthrusong (JED)
          

Get Started