Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Adding Current User Id

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

  • beasty1711
  • beasty1711's Avatar
  • Offline
  • New Member
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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
The administrator has disabled public write access.

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

  • beasty1711
  • beasty1711's Avatar
  • Offline
  • New Member
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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 administrator has disabled public write access.
The following user(s) said Thank You: beasty1711

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

  • beasty1711
  • beasty1711's Avatar
  • Offline
  • New Member
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.

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

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Excellent.
Fast and secure.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.105 seconds

Get Started