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

TOPIC:

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

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

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

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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 following user(s) said Thank You: MorganL

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

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

You can also do:
$model->save(array(
  'id' => $id,
 .. => ..
));
The following user(s) said Thank You: admin, MorganL

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

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Correct.
Coding is now a piece of cake

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

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

This is what you call a component builder. I was able to master using this in a very short time and the resulting component works like a charm. Not just a basic component builder but a fully working component builder with forms fields tables all ready to go. You can make the list and item views to display in the front and back end. Also there is a great forum just starting to evolve and I'm sure this will grow very rapidly when you all realise how good this tool is.
Kevin (JED)

         

Get Started