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

Real time saver and great Component Builder tool ! I have been developing with J-Cook Pro Component Builder for several months now and can say with all honesty that this product/service is second to none. The product is feature rich and is being improved and added to all the time. Do yourself a favor if you need to build a Joomla! Component then you can do no wrong in trying the product. You will save on time and effort while being able to deliver your project on time. J-Cook pro does the hard work for you you then have the freedom to fully customise the end result for your own needs. 

One word: Awesome.
Edwardcox (JED)
         

Get Started