Archive

Archive for September, 2009

Accessing sfGuardPlugin user id.

September 29th, 2009

If you are using sfGuardPlugin all you need to get id of a user that is currently logged in is this:

In your actions.class.php

$user_id = $this->getUser()->getGuardUser()->getId();

But this will cause fatal error if the user is not authenticated. We can prevent this with isAuthenticated().
// /apps/frontend/lib/myUser.class.php

class myUser extends sfGuardSecurityUser
{
     public function getUserId()
     {
        if($this->isAuthenticated())
           return $this->getGuardUser()->getId();
        else
           return 0;
      }
}

Mariusz Actions, Plugins, View

Using Memcached with Symfony 1.2 and Doctrine

September 15th, 2009

Make sure you have Memcached installed.

Add this to ProjectConfiguration.class.php

//ProjectConfiguration.class.php
    public function configureDoctrine(Doctrine_Manager $manager) {
 
        $servers = array(
            'host' => 'localhost',
            'port' => 11211,
            'persistent' => true
        );
 
 
        $cacheDriver = new Doctrine_Cache_Memcache(array(
            'servers' => $servers,
            'compression' => false
            )
        );
 
        //enable Doctrine cache
        $manager = Doctrine_Manager::getInstance();
 
 
 
        $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
 
    }

Add this to your query

 ->useResultCache(true);

Mariusz Actions ,