跳至主要内容

博文

目前显示的是 七月, 2013的博文

jquery file upload with symfony2

for use this plugin, install jquery-file-upload in web install punk_ave bundle and this is my example: /** * @Route("/import",name="prospection_admin_import") * @Template() */ public function importAction(){ $fileUploader = $this->get('punk_ave.file_uploader'); $request = $this->getRequest(); $existingFiles=null; $editId = $request->query->get('editId'); if (!$editId){ $editId=$request->getSession()->get('editId'); } if ($editId){ $existingFiles = $fileUploader->getFiles(array('folder' => '/tmp/attachments/'. $editId)); if ($request->getMethod() == 'POST') { $type=$request->request->get("importType"); $importHandler=$this->get('addepi.prospection.import.handler'); $path=$this->get('kernel')->getRootDir()."/../web/uploads/tmp/attachments/".$editId."/originals/"; f

dynamically change the form presentation

In this article, we discussed how to do it: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html I also give my example : public function buildForm(FormBuilderInterface $builder, array $options) { $factory=$builder->getFormFactory(); $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($factory){ // ... add a choice list of friends of the current application user $address = $event->getData(); $form = $event->getForm(); if ($address instanceof Address && $address->getWebSite()!=""){ $url=$address->getWebSite(); }else{ $url= 'http://www.'; } $form->add($factory->createNamed('webSite','url',$url,array( 'required'=> false, 'attr' => array('class' => 'defaultInvalid'), 'label' => 'form.address.label.webSite&#

regex hint

how to test a char is repeat more than 3 times?  The regex is  /(.)\1{9,}/ . Test: #!perl use warnings ; use strict ; my $regex = qr /(.) \1 { 9 ,}/; print "NO" if "abcdefghijklmno" =~ $regex ; print "YES" if "------------------------" =~ $regex ; print "YES" if "========================" =~ $regex ; Here the  \1  is called a backreference. It references what is captured by the dot  .  between the brackets (.)  and then the  {9,0}  asks for nine or more of the same character. Thus this matches ten or more of any single character. Although the above test script is in Perl, this is very standard regex syntax and should work in any language. In some variants you might need to use more backslashes, e.g. Emacs would make you write  \(.\)\1\{9,\}  here.