Symfony 1.4 Doctrine Extension Blameable w sfGuard
Here’s how to set up the blameable extension for Doctrine 1.2 through Symfony.
1 – in your Symfony project folder, create a folder called “doctrine_extensions” under the lib folder: lib/doctrine_extensions
2 – Download the Blameable extension from Doctrine-project.org and copy it to the newly created doctrine_extensions folder. It should look like this:
lib/doctrine_extensions/Blameable
3 – update you’re yml file actAs section:
myTableClass:
connection: doctrine
tableName: myTableName
actAs:
Blameable:
listener: BlameableSymfony
columns:
created:
disabled: true
updated:
name: updated_by
*NOTE: my db field is called updated_by and i’m not using the created option, so i’ve disabled it. I’ve also created a yml key value called listener. I point the listener to a class called BlameableSymfony, which overrides the doctrine getUserIdentity() to use the sfGuard user id.
4 – Override the Blameable getUserIdentity() method. To do this i create the file lib/doctrine_extensions/Blameable/lib/Doctrine/Template/Listener/BlameableSymfony.php and add this content:
<?php
/**
* extending Doctrine_Template_Listener_Blameable to use symfony sf_guard_user id
*/
class BlameableSymfony extends Doctrine_Template_Listener_Blameable
{
/**
*
* @return int $ident sf_guard_user.id
*/
public function getUserIdentity()
{
$ident = sfContext::getInstance()->getUser()->getGuardUser()->getId();
return $ident;
}
}
That’s it! Good Luck!
i tested this snippet but for some strange reason i get an error if i put doctrine extensions inside a directory other than /lib (e.g lib/doctrine_extensions). symfony doesn’t find files.
suggestions? any help would be highly appreciated. thanks
(sorry for my english… i’m ussing google
jhon,
Doctrine is expecting the files in there. Unless you change the plugin source, you will not be able to change extension directory. Not hard, but you will need to change this each time there is an update.
Hey jhon,
My current set up is as such:
.../symfony apps/ cache/ config/ data/ lib/ doctrine_extentions/ Blamable/ filter/ form/ model/ vendor/ log/ ...If you’ve created the folder in the vendor/symfony/lib, that might be the problem.
Hi,
Just a problem with sfContext and uts –fabulous– message:
The “default” context does not exist.
when coming from php CLI ( symfony console and doctrine:data-load ) for example.
You should use something else to get the user id, (aka: Doctrine_Manager params )
like this:
public function getFiltrableId()
{
$id = Doctrine_Manager::getInstance()->getParam($this->_options['filtrable_column']['name'], ‘doctrine/behavior/filtrable’);
if(is_null($id) && isset($this->_options['filtrable_column']['default'])) {
$id = $this->_options['filtrable_column']['default'];
}
return $id;
}
I’m looking for the Blameable extension, but it looks like Jonathan has just rearranged the Doctrine project website, and the link to the Extensions is not working. Would it be possible for you to email the extension to me?
Thanks,
– brent
I can’t find it either on the website… will advise once we find it.
Cached version of the extensions page:
http://webcache.googleusercontent.com/search?q=cache:bLiIH0w_7iMJ:www.doctrine-project.org/extension/Blameable/1_2-1_0&hl=en&client=safari&gl=us&strip=0
Hope that helps
@Brent Williams
I send an email to Jonathan Wage, and he replied that the extensions can be found at the following URL:
http://svn.doctrine-project.org/extensions/
This plugin seems to have the same functionalities as sfDoctrineActAsSignablePlugin: http://www.symfony-project.org/plugins/sfDoctrineActAsSignablePlugin