JeBy VIP
Total posts: 10
14 Фев 2015 14:29

Hi everyone!

I would like to programatically (so with no frontend or backend form) add a new record to my cobalt website. As I understand I can do this by 'mimicing' the form and using a controller:

            $_POST['jform']['title'] = $mytitle;
            $_POST['jform']['category'] = $mycategoryid;
            $_POST['jform']['section'] = $mysectionid;

            $controller = JControllerLegacy::getInstance('Cobalt');
            $controller->execute('record.save');
            $controller->redirect();

First of all, is there a way of doing this easier? As in not mimicing the form and just having a simple function?

But my main question is: How can I fetch the ID of the record that was just created?

Thanks!

JB

Последние изменения: 16 Фев 2015


JeBy VIP
Total posts: 10
15 Фев 2015 14:14

The status of this topic says "Reviewed" but nobody has replied? Should the status not stay "Open" in this case?


Sergey
Total posts: 13,748
16 Фев 2015 11:20

JeBy The status of this topic says "Reviewed" but nobody has replied? Should the status not stay "Open" in this case?

Reviewd means that some official person read this topic. If there is no answer, it means it is in the process of fix, implementation or transfer to appropriate person.

JeBy First of all, is there a way of doing this easier?

Yes you probably can. You can skeep a lot of steps and call CobaltControllerForm'a save function. But there will be a redirect after that.

Or you can create your own function just store all data correctly. All you need is create correct json for fields column of js_res_record and then values for js_res_record_values. If you have categories the same for categories column and js_res_record_category table.

Работает на Cobalt