Symfony默认使用文本格式存储cache,另外还可以选择SQLite来存储cache,这样简单的数据库系统对存储cache来说效率非常高。
打开factories.yml文件,设置一下参数。

view_cache:
class: sfSQLiteCache
param:
database: %SF_TEMPLATE_CACHE_DIR%/cache.db

如果原来的系统大量的使用了cache,不妨改为SQLite为cache的存储,性能可能会有所改善哦。

简单来说就是登录时实现一个记住密码的功能。

在登录验证中,处理是否需要自动登录功能

  1. class myLogonValidator extends sfValidator
  2. {
  3.   public function initialize ($context, $parameters = null)
  4.   {
  5.     // initialize parent
  6.     parent::initialize($context);
  7.  
  8.     // set defaults
  9.     $this->getParameterHolder()->set('login_error', 'Invalid input');
  10.  
  11.     $this->getParameterHolder()->add($parameters);
  12.  
  13.     return true;
  14.   }
  15.  
  16.   public function execute (&$value, &$error)
  17.   {
  18.  
  19.     $autologon_cookie_param     = $this->getParameterHolder()->get('autologon_cookie');
  20.     $autologon_cookie            = $this->getContext()->getRequest()->getParameter($autologon_cookie_param);   
  21.     $username = $value;
  22.  
  23.   if ( $autoexit_cookie )
  24.    sfContext::getInstance()->getResponse()->setCookie('autologon_cookie', '', time()-3600, '/');
  25.   else 
  26.     sfContext::getInstance()->getResponse()->setCookie('autologon_cookie', $username, time()+2592000, '/');
  27.   return true;
  28. }

这里如果用户选择了自动登录,那么把$username保存到autologon_cookie中
Continue reading »

安全问题修复

如果你在之前项目的action中使用了->sendMail()方法,必须要升级一个补丁http://trac.symfony-project.com/trac/changeset/4380?format=diff&new=4380

PHPMailer  如果调用了sendmail,那么有一个远程攻击漏洞,更多信息请查看http://larholm.com/2007/06/11/phpmailer-0day-remote-execution/

修复了以下bug

  • r4387: fixed input_date_range_tag – Illegal attributes in input tags (#1883)
  • r4385: fixed issue relating to lock files (#1874)
  • r4380: fixed vulnerability in phpmailer with sender (#1871)
  • r4323: fixed DOMDocument E_STRICT warning and trans-unit max id in XLIFF support
  • r4320: fixed sfToolkit::isUTF8() broken for strings larger than some number
  • r4305: added i18n schema for MySQL and SQLite in API documentation

验证数据库的某个字段是否已经存在了相同的数据

首先,在lib目录建立一个 sfCustomUniqueValidator.php

  1. < ?php
  2.   /**
  3. * sfCustomUniqueValidator checks if a record exist in the database with all the mentionned fields.
  4. *
  5. * ex: Check if a companie with company_name exist in country_id
  6. *   class:            sfCustomUniqueValidator
  7. *   param:
  8. *     class:          Companies    //the class on which the search is performed
  9. *     nb_fields:      2            //the number of fields on which the comparison is done
  10. *     field_1:        company_name //First field of the comparison
  11. *     field_2:        country_id   //Other country for the comparison
  12. *
  13. * @package    lib
  14. * @author     Joachim Martin
  15. * @date       15/06/2007
  16. */
  17.  
  18. class sfCustomUniqueValidator extends sfValidator {
  19.  
  20.    /**
  21.    * Executes this validator.
  22.    *
  23.    * @param mixed A file or parameter value/array
  24.    * @param error An error message reference
  25.    *
  26.    * @return bool true, if this validator executes successfully, otherwise false
  27.    */
  28.  
  29.     public function execute(&$value, &$error) {
  30.  
  31.         $className  = $this->getParameter('class').'Peer';
  32.  
  33.         //Get fields number
  34.         $nb_fields = $this->getParameter('nb_fields');
  35.  
  36.         //Define new criteria      
  37.         $c = new Criteria();
  38.  
  39.         //Loop on the fields
  40.         for($i = 1; $i < = $nb_fields ; $i++) {
  41.             //Retrieve field_$i
  42.             $check_param = $this->getParameterHolder()->get("field_$i");
  43.             $check_value = $this->getContext()->getRequest()->getParameter($check_param);
  44.  
  45.             //If check value defined       
  46.             if ($check_value != '') {  
  47.                 //Adding field to the criteria
  48.                 $columnName = call_user_func(array($className, 'translateFieldName'), $check_param, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
  49.                 $c->add($columnName, $check_value);
  50.             }
  51.         }
  52.  
  53.         $object = call_user_func(array($className, 'doSelectOne'), $c);
  54.  
  55.         if ($object)
  56.         {
  57.           $tableMap = call_user_func(array($className, 'getTableMap'));
  58.           foreach ($tableMap->getColumns() as $column)
  59.           {
  60.             if (!$column->isPrimaryKey())
  61.             {
  62.               continue;
  63.             }
  64.  
  65.             $method = 'get'.$column->getPhpName();
  66.             $primaryKey = call_user_func(array($className, 'translateFieldName'), $column->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME);
  67.             if ($object->$method() != $this->getContext()->getRequest()->getParameter($primaryKey))
  68.             {
  69.               $error = $this->getParameter('custom_unique_error');
  70.  
  71.               return false;
  72.             }
  73.           }
  74.         }
  75.  
  76.         return true;
  77.     } 
  78.  
  79.     public function initialize ($context, $parameters = null) {
  80.         // initialize parent
  81.         parent::initialize($context);
  82.  
  83.         //Set default parameters value
  84.         $this->setParameter('custom_unique_error','The value is not unique');
  85.  
  86.         $this->getParameterHolder()->add($parameters);
  87.  
  88.         // check parameters
  89.         if (!$this->getParameter('class'))
  90.         {
  91.           throw new sfValidatorException('The "class" parameter is mandatory for the sfCustomUniqueValidator validator.');
  92.         }
  93.  
  94.         if (!$this->getParameter('nb_fields'))
  95.         {
  96.           throw new sfValidatorException('The "nb_fields" parameter is mandatory for the sfCustomUniqueValidator validator.');
  97.         }
  98.  
  99.         return true;
  100.     }
  101. }

调用方法: Continue reading »

没有增加新功能,只是修复了一些bug

  • r4286: fixed sfBrowser keeps previous Dom is response is not XHTML (#1853)
  • r4282: fixed sfValidatorManager refuses zero values as null values (#1649)
  • r4277: fixed generator themes in the project data directory do not override data in plugin directory (#1813)
  • r4266: fixed $request->hasError() should return true on errors with empty message (#1864)
  • r4264: fixed usage of components in admin generator generator.yml (#1809)
  • r4262: added some unit tests for symfony escaping mecanism
  • r4250: fixed include_blank being forced to ‘true’ in admin generator (#1739)
  • r4242: fixed a typo in MySQL i18n message source
  • r4240: added an exception when a YAML file contains tabs instead of spaces when tabs are mixed with spaces
  • r4238: replaced all occurences of deprecated function
  • mysql_escape_string() by mysql_real_escape_string() (#1860)

  • r4236: fixed bug for adjacent CSS selector
  • r4228: fixed a bug in URL generation for route names having a star in the middle
  • r4205: fixed _edit_form.php in Admin Generator should have have an action of save, not edit (#1812)
  • r4203: fixed sf_check_lock and sf_check_symfony has no effect (#1675)
  • r4199, r4201: fixed input_date_tag with same name but different ids (#1568)
  • r4195: fixed link_to_if() inserts parameter in html (#1700)
  • updated lime to 1.0.4 (fixes php 5.2.2 support)

As for every 1.0.X release, after upgrading to 1.0.4, don’t forget to clear the cache of your projects.

在玩儿一些程序的时候发现,用浏览器访问和用手机访问同一个网站会出现不同的界面,比如:v2ex

symfony可以通过Filter来实现这个功能:

在lib目录内添加一个myEnvironmentLayoutFilter.class.php文件。 Continue reading »

© 2011 刘敏的Blog Suffusion theme by Sayontan Sinha