- Posts: 19
COMMUNITY FORUM
[SOLVED] how to change item via code?
- vtmod
-
Topic Author
- Offline
- New Member
Less
More
8 years 11 months ago #155040
by vtmod
how to change item via code? was created by vtmod
Hi,
Sorry if I am wrong here (tried the forum and searched the Code and SO), but how would one update an item's data via code?
$row = JTable::getInstance('K2Item', 'Table');
$row->load($myId);
$row->title = 'New title';
$row->save(); // doesn't work
$row->checkin(); // doesn't work too
thanks a lot,
g
Sorry if I am wrong here (tried the forum and searched the Code and SO), but how would one update an item's data via code?
$row = JTable::getInstance('K2Item', 'Table');
$row->load($myId);
$row->title = 'New title';
$row->save(); // doesn't work
$row->checkin(); // doesn't work too
thanks a lot,
g
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
8 years 11 months ago #155045
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic how to change item via code?
Hello,
I think you need to look at the K2 item model class for this purpose.
I think you need to look at the K2 item model class for this purpose.
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- vtmod
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 19
8 years 11 months ago #155046
by vtmod
Replied by vtmod on topic how to change item via code?
thank you,
this is what I did and the code above is all I could figure out.
Seems like that this is a end-user forum only, so this question is better to be asked on Stackoverflow ?
this is what I did and the code above is all I could figure out.
Seems like that this is a end-user forum only, so this question is better to be asked on Stackoverflow ?
Please Log in or Create an account to join the conversation.
- vtmod
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 19
8 years 11 months ago #155049
by vtmod
Replied by vtmod on topic how to change item via code?
So i asked this now on Stackoverflow : stackoverflow.com/questions/37651789/how-to-change-joomla-k2-item-via-code
g
g
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
8 years 11 months ago #155070
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic how to change item via code?
It depends on where do you run this code, so you may need to include specific classes for example.
Also, what does it mean "doesn't work"?
Do you find any php error? if yes, what is the error message?
Please provide more details to get the correct answer.
Also, what does it mean "doesn't work"?
Do you find any php error? if yes, what is the error message?
Please provide more details to get the correct answer.
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- vtmod
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 19
8 years 11 months ago - 8 years 11 months ago #155072
by vtmod
Replied by vtmod on topic how to change item via code?
Hi,
The code is used within a custom Joomla plugin whereby only the very basics of Joomla/K2 are loaded. Its part of a sort of stand-alone application (sort of command line application if you like) . So there are no request variables or similar.
By "doesn't work" I mean : the item is not updated in the database, so there is also no change to see in the back-end.
There is also no error, anywhere (i have very pedantic & verbose debug settings showing pretty much all ). The code also proceeds so there was no fatal error or similar.
Thanks a lot for popping up.
Maybe there is a K2 plugin doing this kind of thing, something i could paste over...
The code is used within a custom Joomla plugin whereby only the very basics of Joomla/K2 are loaded. Its part of a sort of stand-alone application (sort of command line application if you like) . So there are no request variables or similar.
By "doesn't work" I mean : the item is not updated in the database, so there is also no change to see in the back-end.
There is also no error, anywhere (i have very pedantic & verbose debug settings showing pretty much all ). The code also proceeds so there was no fatal error or similar.
Thanks a lot for popping up.
Maybe there is a K2 plugin doing this kind of thing, something i could paste over...
Last edit: 8 years 11 months ago by vtmod.
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
8 years 11 months ago #155073
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic how to change item via code?
Hi,
After a quick review for the backend item model class 'administrator/components/com_k2/models/item.php' and inspecting the K2ModelItem::save() method, I think you should callinstead of
After a quick review for the backend item model class 'administrator/components/com_k2/models/item.php' and inspecting the K2ModelItem::save() method, I think you should call
$row->store();
$row->save();
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- vtmod
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 19
8 years 11 months ago #155080
by vtmod
Replied by vtmod on topic how to change item via code?
worked!
thanks a lot !
thanks a lot !
Please Log in or Create an account to join the conversation.