Welcome, Guest
Username: Password: Remember me

TOPIC: UPDATE'ing an existing record

UPDATE'ing an existing record 10 Apr 2016 13:24 #13894

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I know how to update a record the 'Joomla way', however of late I have started using a much more neat way which uses J-Cook models.

i,.e here is a little routine that grabs the ID of a newly created record and posts a record into a foreign table (status update)
    $updatemodel = CkJModel::getInstance('statusupdate', 'mycomponentModel');
    
    $table = JTable::getInstance('venue', 'mymodelTable');
    $newid = $table->getDBO()->insertid(),
    
    $result = $updatemodel ->save(
        array(
            'venue' => $newid,
            'summary' => 'Added the Venue '. $data['name'],
            'detail' => 'Why not checkout the latest addition to the platform',
            'type' => 'venue',
            'link' => 'index.php?option=com_mycomponent&view=deals&Itemid=105&filter_venue='.$newid,
            'created_by' => $user->id,
            'creation_date' => $creation_date
        )
    );

what is the EQUIVALENT process for UPDATING a record, not creating a new one.

I.e if I have the ID of the record $data and want to update the longtitude and latitude of the record with $long and $lat (which I have obtained through another process

I assume I will be using
$result = $updatemodel ->update(

but where do I put the 'where' condition?

I know where to put this in the model itself, I just need the syntax
Morgan Leecy MCSE

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

UPDATE'ing an existing record 10 Apr 2016 18:24 #13896

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
For a 'venue' item, the state var is 'venue.id'

Simple as that :
$model->setState('venue.id', $id);
$model->save(array(
.. => ..
));
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL

UPDATE'ing an existing record 11 Apr 2016 10:52 #13902

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
You can also do:
$model->save(array(
  'id' => $id,
 .. => ..
));
The administrator has disabled public write access.
The following user(s) said Thank You: admin, MorganL

UPDATE'ing an existing record 18 Apr 2016 09:33 #13916

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Correct.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.072 seconds

Get Started