Archive for category Symfony

Session time out in Symfony

Quick solution in symfony 1.0.xx


all:
.settings:
timeout: 86400

Just be careful because if you set to false it will disable sessions

Tags: , ,

Symfony – Sorting elements in filters (foreign table)

Today i found nice and simple solution how to filter elements in dropdown when you specify filter for field which is forgeign key.

Simple go and edit Peer class of table you want to have things sorted.

class [YOURTABLE]Peer extends Base[YOURTABLE]Peer
{
  public static function addSelectColumns(Criteria $criteria)
  {
    parent::addSelectColumns($criteria);
    $criteria->addAscendingOrderByColumn(self::[FIELD YOU WANT TO SORT BY]);
  }
}

Tags: , , ,

Logging page rendering time in Symfony 1.xx

Change your SF_APP/web/index.php file to be:

$timer = sfTimerManager::getTimer('myTimer');
sfContext::getInstance()->getController()->dispatch();
$timer->addTime();
$elapsedTime = $timer->getElapsedTime();
$fullRealUri = str_replace( sfContext::getInstance()->getRequest()->getUriPrefix(), "", sfContext::getInstance()->getRequest()->getUri());
file_put_contents('/tmp/time.log',date('Y-m-d H:i:s')."|$fullRealUri|$elapsedTime\n\r",FILE_APPEND);

Tags: , , ,

Symfony admin generator problem

When you change your schema.yml file, especially removing column which you used before for sorting you can have face problem with 500 internal server error. Why?

If you look closer into cache directory with auto-generated files
you can see:

protected function addSortCriteria($c)
{
if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/tag_elements/sort'))
{
$sort_column = TagElementsPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);

So the sort element comes from SESSION! Even when you clear cache (symfony cc), session stays same.

Whenever you do changes, clear browser cache!

Affects Symfony 1.0.17

Tags: , ,

sfMemcachePlugin limitations

I’m using quite hapilly sfMemcachePlugin, but recently i needed to store object which was around 2Mb, and problems started. I’ve spend couple minutes trying to figure out why app is not working, finally i Found that memcache doesn’t store stuff more than 1Mb. To solve that, I’ve decided to compress data and then store it, but if data is still over limit i’m switching to sessions anyway.

if (!extension_loaded('zlib'))
{
// there is 1024Kb limitation on memcache, so we need to compress
$this->_storing_method = 'sessions';
}
 
	public function someFunctionToStoreData()
	{
		if ($this->_storing_method=='sessions')
		{
			sfContext::getInstance()->getUser()->setAttribute('variableId',$this->_varToStore);
		} else
		{
			// compress
                        $data = gzcompress(serialize($this->_varToStore),9);
			// compute data size
                        $data_size = strlen($data)/1024/1024;
                        // log it in symfony
			sfContext::getInstance()->getLogger()->info('Data size for memcache to store is '.$data_size." Mb");
                        // check data size - 0.9Mb - just in case to not go over 1Mb
			if ($data_size>0.9)
			{
				$this->_storing_method='sessions';
				$this->someFunctionToStoreData();
			}
			sfMemcacheFunctionCache::getInstance()->set( 'variableId', 'OurNameSpace', $data);
		}
		sfContext::getInstance()->getLogger()->info('Setting search ordering variable for country '.$this->_locationId);
	}

Tags: , ,