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

TOPIC:

Adding Current User Id 05 Sep 2013 08:53 #10975

Hi,
Im struggling to get my head around MVC.

I need to track the current user id that created an item and then save it to my db.

I managed it in v1.5 of jcook by editing the prepare table function, but im struggling to see where to go in v2.5.5


Is there a way of doing this easily via the builder?

if not, where do i go?
I've put the hidden field on my form (which is picking up the correct value), however this value not getting inserted into the DB.

ive tried to fork loadFormData but this doesn't seem to have helped.

Any help would be appreciated thanks

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

Adding Current User Id 05 Sep 2013 09:51 #10984

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
You probably have the authoring fields not properly named.

Since Cook 2.0, some fields must be named in a correct way.
'published', 'checked_out', 'created_by', ... are unchangeable field names.
Maybe your authoring field is still named 'author'

Edit and save your field it will fix it, replacing by the correct name.

Hope it helps.
Coding is now a piece of cake

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

Adding Current User Id 05 Sep 2013 10:32 #10991

thanks for responding.

In my item form i have this:
<input type="hidden" name="parent" id="parent" value="<?php echo (int)JFactory::getUser()->get('id'); ?>" />

Which sets the value correctly when the form loads, but this is not getting sent to the database table.

My database column is called parent. The other fields on my form are saving correctly.

thanks

Pete

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

Adding Current User Id 05 Sep 2013 11:48 #10992

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
name="jform[parent]"

But it is not safe at all.
Hidden input can be hacked.
You must look at your code in the model.
-> prepareTable()
Coding is now a piece of cake
The following user(s) said Thank You: beasty1711

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

Adding Current User Id 05 Sep 2013 13:39 #11005

Ahh fixed.

Model file didn't have a prepareTable function which is what was throwing my.

created one manually, and added $table->parent = JFactory::getUser()->get('id'); and everything appears to work.

Ta

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

Adding Current User Id 05 Sep 2013 13:50 #11007

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Excellent.
Fast and secure.
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.062 seconds

I would like to Thank you for the Speed and the Quality of your work.
Pantelis (Forum)

Get Started