Symfony默认使用文本格式存储cache,另外还可以选择SQLite来存储cache,这样简单的数据库系统对存储cache来说效率非常高。
打开factories.yml文件,设置一下参数。
view_cache:
class: sfSQLiteCache
param:
database: %SF_TEMPLATE_CACHE_DIR%/cache.db
如果原来的系统大量的使用了cache,不妨改为SQLite为cache的存储,性能可能会有所改善哦。
八 142007
七 032007
简单来说就是登录时实现一个记住密码的功能。
在登录验证中,处理是否需要自动登录功能
- class myLogonValidator extends sfValidator
- {
- public function initialize ($context, $parameters = null)
- {
- // initialize parent
- parent::initialize($context);
- // set defaults
- $this->getParameterHolder()->set('login_error', 'Invalid input');
- $this->getParameterHolder()->add($parameters);
- return true;
- }
- public function execute (&$value, &$error)
- {
- $autologon_cookie_param = $this->getParameterHolder()->get('autologon_cookie');
- $autologon_cookie = $this->getContext()->getRequest()->getParameter($autologon_cookie_param);
- $username = $value;
- if ( $autoexit_cookie )
- sfContext::getInstance()->getResponse()->setCookie('autologon_cookie', '', time()-3600, '/');
- else
- sfContext::getInstance()->getResponse()->setCookie('autologon_cookie', $username, time()+2592000, '/');
- return true;
- }
这里如果用户选择了自动登录,那么把$username保存到autologon_cookie中
Continue reading »
六 262007
安全问题修复
如果你在之前项目的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
- < ?php
- /**
- * sfCustomUniqueValidator checks if a record exist in the database with all the mentionned fields.
- *
- * ex: Check if a companie with company_name exist in country_id
- * class: sfCustomUniqueValidator
- * param:
- * class: Companies //the class on which the search is performed
- * nb_fields: 2 //the number of fields on which the comparison is done
- * field_1: company_name //First field of the comparison
- * field_2: country_id //Other country for the comparison
- *
- * @package lib
- * @author Joachim Martin
- * @date 15/06/2007
- */
- class sfCustomUniqueValidator extends sfValidator {
- /**
- * Executes this validator.
- *
- * @param mixed A file or parameter value/array
- * @param error An error message reference
- *
- * @return bool true, if this validator executes successfully, otherwise false
- */
- public function execute(&$value, &$error) {
- $className = $this->getParameter('class').'Peer';
- //Get fields number
- $nb_fields = $this->getParameter('nb_fields');
- //Define new criteria
- $c = new Criteria();
- //Loop on the fields
- for($i = 1; $i < = $nb_fields ; $i++) {
- //Retrieve field_$i
- $check_param = $this->getParameterHolder()->get("field_$i");
- $check_value = $this->getContext()->getRequest()->getParameter($check_param);
- //If check value defined
- if ($check_value != '') {
- //Adding field to the criteria
- $columnName = call_user_func(array($className, 'translateFieldName'), $check_param, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
- $c->add($columnName, $check_value);
- }
- }
- $object = call_user_func(array($className, 'doSelectOne'), $c);
- if ($object)
- {
- $tableMap = call_user_func(array($className, 'getTableMap'));
- foreach ($tableMap->getColumns() as $column)
- {
- if (!$column->isPrimaryKey())
- {
- continue;
- }
- $method = 'get'.$column->getPhpName();
- $primaryKey = call_user_func(array($className, 'translateFieldName'), $column->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME);
- if ($object->$method() != $this->getContext()->getRequest()->getParameter($primaryKey))
- {
- $error = $this->getParameter('custom_unique_error');
- return false;
- }
- }
- }
- return true;
- }
- public function initialize ($context, $parameters = null) {
- // initialize parent
- parent::initialize($context);
- //Set default parameters value
- $this->setParameter('custom_unique_error','The value is not unique');
- $this->getParameterHolder()->add($parameters);
- // check parameters
- if (!$this->getParameter('class'))
- {
- throw new sfValidatorException('The "class" parameter is mandatory for the sfCustomUniqueValidator validator.');
- }
- if (!$this->getParameter('nb_fields'))
- {
- throw new sfValidatorException('The "nb_fields" parameter is mandatory for the sfCustomUniqueValidator validator.');
- }
- return true;
- }
- }
调用方法: Continue reading »
六 212007
没有增加新功能,只是修复了一些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
- 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)
mysql_escape_string() by mysql_real_escape_string() (#1860)
As for every 1.0.X release, after upgrading to 1.0.4, don’t forget to clear the cache of your projects.
六 152007
在玩儿一些程序的时候发现,用浏览器访问和用手机访问同一个网站会出现不同的界面,比如:v2ex
symfony可以通过Filter来实现这个功能:
在lib目录内添加一个myEnvironmentLayoutFilter.class.php文件。 Continue reading »