Category Archives: symfony 知识
symfony 调用不同app的routing
http://www.symfony-project.org/blog/2009/02/17/cross-application-links
symfony 中文等匹配 sfValidatorRegex()
new sfValidatorRegex( array( ‘pattern’ => ‘/^[^\W]?[a-zA-Z0-9\x{4e00}-\x{9fa5}_\s]*[^\W]?$/u’), array( ‘invalid’=>’昵称包含限制字符,请使用中文、英文和数字’, ) 以下为转的: 2E80~33FFh:中日韩符号区。收容康熙字典部首、中日韩辅助部首、注音符号、日本假名、韩文音符,中日韩的符号、标点、带圈或带括符文数字、月份,以及日本的假名组合、单位、年号、月份、日期、时间等。 3400~4DFFh:中日韩认同表意文字扩充A区,总计收容6,582个中日韩汉字。 4E00~9FFFh:中日韩认同表意文字区,总计收容20,902个中日韩汉字。 A000~A4FFh:彝族文字区,收容中国南方彝族文字和字根。 AC00~D7FFh:韩文拼音组合字区,收容以韩文音符拼成的文字。 F900~FAFFh:中日韩兼容表意文字区,总计收容302个中日韩汉字。 FB00~FFFDh:文字表现形式区,收容组合拉丁文字、希伯来文、阿拉伯文、中日韩直式标点、小符号、半角符号、全角符号等。 比如需要匹配所有中日韩非符号字符,那么正则表达式应该是^[\u3400-\u9FFF]+$ 理论上没错, 可是我到msn.co.ko随便复制了个韩文下来, 发现根本不对, 诡异 再到msn.co.jp复制了个 ‘お ‘, 也不得行.. 然后把范围扩大到^[\u2E80-\u9FFF]+$, 这样倒是都通过了, 这个应该就是匹配中日韩文字的正则表达式了, 包括我們臺灣省還在盲目使用的繁體中文 而关于中文的正则表达式, 应该是^[\u4E00-\u9FFF]+$, 和论坛里常被人提起的^[\u4E00-\u9FA5]+$很接近 需要注意的是论坛里说的 ^[\u4E00-\u9FA5]+$这是专门用于匹配简体中文的正则表达式, 实际上繁体字也在里面, 我用测试器测试了下 ‘中華人民共和國 ‘, 也通过了, … Continue reading
symfony 1.4 embedForm 保存2次问题
When a form is embedded, the embedded model representation is saved twice: one via fromArray(), that automatically hydrates related components, and another time via saveEmbeddedForm. 使用embed会出现insert 2次的问题 configure(){ embedRelation(‘ForwardProfile’); } function addProfile(){ //embed a new form $profiles = new sfForm(); … Continue reading
symfony 关联id必须unset才会自动添加
数据库结构2个表: user ———- id name ———- book ———- id user_id(fk) name ———- bookForm.class.php的configure()设置 unset($this['user_id']); 这样embedForm后,user_id值自动添加为user的id值
添加多条记录,字段为空则不添加(bind)
目的: 用户自定义数目的记录,有内容的input则插入数据库,没内容则忽略 例子: 已经embed的字段要用unset()才不会插入数据库 /lib/…/xxForm.class.php … public function addNewTargets($number) { $targets = new sfForm(); for($i=0;$i<$number;$i++) { $target = new WeightTarget(); $target->setWeightWatcher($this->getObject()); $target_from = new WeightTargetForm($target); $targets->embedForm($i, $target_from); } $this->embedForm(‘new’, $targets); } public function bind(array $taintedValues = null, array $taintedFiles = … Continue reading
Embedded forms with symfony 1.4 and jQuery
http://tech.cibul.org/embedded-forms-with-symfony-1-4-and-jquery/ How to implement a single interface to insert multiple entries linked by one-to-many relations… I’ve been looking recently for a way to build a form that would allow the input of data (edition or adding new data) into multiple … Continue reading
symfony上传文件
symfony 1.2 利用form类,设置文件上传。 class WorldImagesForm extends BaseWorldImagesForm { public function configure() { $this->widgetSchema['file'] = new sfWidgetFormInputFile(); $this->validatorSchema['file'] = new sfValidatorFile(array( ‘required’ => false, ‘path’ => sfConfig::get(‘sf_upload_dir’).’/images/guide’, ‘max_size’ => ’5242880′, ‘mime_types’ => ‘web_images’), array( ‘max_size’ => ‘最大15Mb!’, ‘mime_types’ => ‘只支持web图片格式’ )); … Continue reading
图片验证扩展sfValidatorFileImage
http://snippets.symfony-project.org/snippet/343
symfony生产url
在symfony中生产url的helper函数url_for很好用。但它只能在模板中使用,而在其它的地方需要使用不同的函数
sfPropelRouteCollection路由类
sfPropelRouteCollection从名字来看就是多个sfPropelRoute的集合,它包括哪些路由呢?
symfony1.2中直接执行SQL语句
symfony支持propel1.3,propelPDO继承了mysql PDO的函数,所以可以直接使用mysql PDO的函数直接执行SQL语句。
symfony实现2级联动菜单(2)
The table sql statments can’t be edited into previous snippet, so paste here
symfony实现2级联动菜单(1)
There are two multi-select box, the first one is parent list menu