[Catalyst] Where to put common functions & how to get user id
jakac
jakac at iprom.si
Tue May 27 07:13:06 BST 2008
Hello!
Can someone please explain where should I put common functions such as
"action logging" (my app is designed so that it actually logs any =
inserts/updates
of data)?
My table for logging this data is called "worklog" and contains =
following columns:
* id
* date
* time
* user_id (integer)
* action (text)
in my older (non-catalyst) application I had a common function defined as:
sub workLog {
my ($dbh,$user_id,$action) =3D @_;
return $dbh->do("insert into worklog user_id,action values =
('$user_id','$action');");
}
And whenever I needed to log something I just used a call like:
&workLog($dbh,$user_id, ' User updated table foo column bar');
So now I am wondering how to simply implement a call like this into =
catalyst?
Also the other thing is - how to get active user's ID? When I =
authenticate my user
using Authentication plugin (using $c->login($username,$password)) the =
$c->user->id
contains that user's username and not his ID.
My users table contains following columns:
* user_id
* username
* password
* first name, last name etc.......
user authenticates using his username&password just like in "Catalyst =
authentication tutorial"
but my application always needs user's ID so I always have to search for =
this user in the
database...
my $thisuser =3D $c->model('MyDB::Users')->find({username =3D> $c->user->id=
});
my $thisuser_id =3D $thisuser->user_id;
Is there a simpler way to do it? I need current user's ID in almost =
every controller all the time...
Thank you!
JC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080527/8a3ea=
09d/attachment.htm
More information about the Catalyst
mailing list