跳至主要内容

博文

目前显示的是 2012的博文

symfony2 translator in formtype class

this should works, $builder ->add('select','choice',array( 'multiple'=>false, 'expanded'=>true, 'choices' => array('0'=>'form.search.label.all','1' => 'form.search.label.select','2'=>'form.search.label.unselect'), 'required' => false,)) this also: $builder->add('givenTakenEmail','email', array('label' => 'overview.marker.new.given_taken_email', 'read_only' => $readOnly, 'required' => true,) );

CSS LESS

Less 能让你更方便的写css,就像写程序一样,可以继承,可以设置变量。 请看这篇文章介绍如何在symfony2下安装less http://www.yves-astier.com/2012/09/20/symfony-2-comment-integrer-less/ and http://www.symfony-grenoble.fr/80/utiliser-less-avec-assetics-de-symfony2/ 这是它的官网: http://lesscss.org/ in syfmony2 , how to combine cssrewrite, yui and less? here is the answer: {% stylesheets debug=false filter='lessphp,?cssrewrite,?yui_css' output='css/moderation.css' "bundles/acmemoderation/css/*.less" %}

how to customize collection form type with prototype

well, if you use a form prototype in symfony2, you can not custmize his presentation like you usually do, like some template file. Except you write a customize form type to render your form. This is a trick: This was bugging me too. I customized a field type and even made simple form types with a reduced fieldset (for more complex objects), but it just didn't feel right. I've come up with a solution that should do the trick :) First - I think your   should be outside your loop. Next, your prototype is just a form view object, so if you pass it to a template you can render fields by hand and customize the output. Note: autoescape has no effect on included content, so use 'filter escape'. id = "playerFields" data-prototype = "{% filter escape %}{% include 'AcmeTeamBundle:Team:prototypePlayer.html.twig' with {'form': form.players.get('prototype')} %}{% endfilter %}" > Then in your prototypePlayer.html.twig, ju

symfony2 Assetic Css rewrite problem.

well, as we all know, the @CordovaXBundle/Resources/public/css/main1.css does not work. so we can set assetic:     use_controller: true in dev config, and then use assets:install to move all you css and photos in web folder. then ,you can just use the method proposed in : http://www.craftitonline.com/2011/06/symfony2-beautify-with-assetic-and-a-template-part-ii/ And this is become a one step work, you need only run assets:install every time you make any modification. Well, if you use linux, and you use assets:install --symlink then you do not even need this step.

fosjsRouter

when you set : assetic:     use_controller: true but you still use php app/consol assetic:dump the new modification will not take in consideration. You need to remove both the : xxx_router_xx.js xxx_fos_js_routes_xx.js from the web folder. And after that , the contoller will in use.

serialize a object in sesssion,

You can serialize any entity by setting all their properties and relationships from  private  to  protected . You could have a common issue with  symfony2 , even if you have set all properties to protected: You have to re-generate the proxies of those entities you have changed. To do so, simply clear the cache. For  dev enviroment : app/console cache:clear It works even if "it contains many foreign objects and even ArrayCollections of foreign entities" as you said.

share js /css between bundles

see:  http://stackoverflow.com/questions/11192568/symfony2-how-to-share-js-libs-and-css-between-bundles If you want to share common assets among all your bundles, the best choice is to place them in the app/Resources/public  directory. For example: app/Resources/Public |-- css | `-- base.css |-- js | `-- jquery.js Then you can reference them in your layout as follow: {% block stylesheets %} {% stylesheets '../app/Resources/public/css/*' %} {% endstylesheets %} {% endblock %} {% block javascripts %} {% javascripts '../app/Resources/public/js/*' %} {% endjavascripts %} {% endblock %}

clear swf upload queue:

// request your stat objects, it contains amongst others the number of files in the queue var stats = my_upload . getStats (); // while the queue is not empty ... while ( stats . files_queued > 0 ) { // .. cancel the first in the queue (null: take the first found, false: don't trigger an error event) my_upload . cancelUpload ( null , false ); // it is important to reload the stats everytime and not just do a for (i = 0; i < stats.files_queued ... stats = my_upload . getStats (); } This can be done by thisway in handler.js: function uploadAnnoncePhotoSuccess(file, serverData) { try { var progress = new FileProgress(file, this.customSettings.upload_target); if (serverData.substring(0, 9) === "FILENAME:") { $(".photo_loading").hide(); var imgName=serverData.substring(9); tabImgs[tabImgs.length] = imgName; setImgsTab(); //copy annonce is like a new annonce. if (id_annonce && 'copy'!=photoAct

cache:clear

 if you get this kind of shit: require(): Failed opening required 'app/cache/prod/doctrine/orm/Proxies/__CG__cgswebsdBundleEntityCategoria.php' (include_path='.:/usr/share/php:/usr/share/pear') in vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php on line 92 so if you remove entirely the cache/prod: Run "app/console cache:warmup --env=prod --no-debug". Running cache:clear does the cache warming by default (i.e. when you don't add the --no-warmup option).  see the discussion:  ------------- Well normally he shouldn't have to run this command, the kernel should trigger the cache warming if the cached container doesn't exists (which is the case when you delete the entire folder). Maybe it's because of a configuration of php, avoiding to detect that the cached container doesn't exists, apc.stat for example. --------------- The kernel only triggers some cache warmers, not all of them. The commands run them all (by def

symfony2 pass parameter to query_builder in form type

public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('cityName','entity',array( 'class' => 'ModerationBundle:TVille', 'query_builder' => function(EntityRepository $er) use ($options) { return $er->createQueryBuilder('u') ->where('u.section = :id') ->setParameter('id', $options['id']) ->orderBy('u.root', 'ASC') ->addOrderBy('u.lft', 'ASC'); },); In this way we can pass the parameter to query builder. and the options sould passed by this way: $form = $this->createForm(new ProductType(), $product, array('id' => $id ));

google map locator

在输入框中键入地址,google地图找到相应的位置,同时也提供地址补全。 1.  http://code.google.com/p/geo-autocomplete/ 2.  http://mootools.net/forge/p/geosuggester 好像都是免费的,我以前做的那个简直弱爆了。

其实一直都想把这首歌改改

有了共产党,就没有新中国, 有了共产党,就没有新中国, 共产党,它阉割了中华民族 共产党,它一心独裁中国, 它领导人民走向深渊, 它领导人民走向死亡, 它剽窃了抗战的果实, 它饿死了无数人民, 它消灭我们的文化, 它创造了一个巨大的囚笼。 有了共产党,就没有新中国 repeat.

据说是李大眼在北大的讲话

看起来是他的风格,看了天涯的评论,颇有一番当年鲁迅写人血馒头的感慨。    李承鹏北大演讲录——说话   今天受邀来到北大,站在胡适、陈独秀,李大钊,傅斯年、徐志摩,俞平伯这些熠熠生辉的名字下,免不了要谈谈“思想自由,兼容并包”。可这个话题太大,我只能谈一个小话题。在我看来,“兼容并包”,无非各种观点,“思想自由”最直接体现,正是言论自由。所以今天我谈的话题是:说话。   中国人正在失却说话的能力。   说话,差不多是动物的本能。雨停了,鸟儿就开心地叫。花开了,蜜峰就嗡嗡地来。春天来了,公狼闻到五华里外母狼的味道,仰脖兴奋地大声嗷嗷。人类作为高级动物最简单的说话是:我饿了。婴儿饿了会哭,那是婴儿的语言。连婴儿饿了都会表达,可是在五十年前也就是1960-1962那三年,这个星球有整整六亿人怎能说自己饿呀。本能告诉你饿了,你却不能说自己饿了……因为那就是给社会主义国家丢脸。怎么产两万斤,红太阳永远正确,我们得勒紧裤腰带把粮食支援给兄弟们,就不能说自己饿了。在大饥荒,整个民族失语,不仅在政治斗争中欺骗亲戚朋友父母,连自己的胃也要欺骗。   当时的报纸为了表现大丰收,照片上茂密的庄稼上面还躺着几个大胖小子。后来才知道,那是把十几亩地里的庄稼移植到一亩地里。由于密不透风,那些庄稼很快也死掉。可这个官方话语体系里不会有真相,大家彼此都假装相信大丰收是真的,饿了却是假的。可是你们那个著名的图书管理员是农村出身,却不明白?彭德怀也是农民出身,有一次就说了真话,这个亩产量不太可能吧……后来,他的遭遇大家想必是知道的。   不仅饿了不能说,连“我爱你”也不能公开地说。大家都读过“关关雎鸠,在河之洲”,鸟儿也会歌唱自己的爱情,可那时候,人却不许这么说。因为那是封资修。我小时候在新疆,最喜欢看抓破鞋……那时特别爱抓破鞋,那时对破鞋的定义不仅是奸夫淫妇,野地里搞对象也算搞破鞋。可是我觉得相比其他各种类型的坏人,破鞋的貌似长得好看些,也更有才艺。那时哈密有个露天的“小河沟电影院”,清凉的河水从天山蜿蜒而下,两岸长着些胡杨,破鞋们沿河岸边走边交待怎么搞上的破鞋、如何接头、如何亲嘴……虽然剩下的就不许讲了,但仅仅这样已让我觉得很有趣。因为他们说的全是电影院、课本里看不到的,是真话,是人性。   有个姓安的小伙总被抓,他不仅喜欢在野外搞破鞋,还要吹着萨克斯风搞。这就是他的话语方式,他

php doctrine findby

sometimes it will take a very time to run, i got this example: public function receiveAction() { $originData=$this->get('request')->request->get('data'); if (!isset($originData)){ $response = new Response(json_encode(array('msg' => 'error,no data'))); $response->headers->set('Content-Type', 'application/json'); return $response; } $data = json_decode( $originData ); if (!is_array($data)){ $response = new Response(json_encode(array('msg' => 'error,data is not correct:'.$originData))); $response->headers->set('Content-Type', 'application/json'); return $response; } $em=$this->getDoctrine()->getEntityManager('webscraper'); foreach($data as $row){ if (!isset($row[0])) continue; /* $ad=$em->getRepository('AcmeDataCollectionBundle:SmallAdds'

install god dame fastgci and fpm on our server.

first of all, need to create a child process of CGI which located in /etc/init.d/php-common-Perso.sh prefix="/opt/php-5.3.6-full"; exec_prefix=${prefix}; php_fpm_BIN="${exec_prefix}/sbin/php-fpm"; php_fpm_CONF="/home/siteadm/common/php/Perso.conf"; php_fpm_PID="/home/siteadm/common/php/Perso.pid"; php_fpm_INI="/home/siteadm/common/php/Perso.ini"; PHP_INI_SCAN_DIR="/home/siteadm/common/php/vhost"; php_opts="--fpm-config $php_fpm_CONF -c $php_fpm_INI" export PHP_INI_SCAN_DIR; . /home/siteadm_admin/template/php/php-fpm-init.sh the PHP_INI_SCAN_DIR include all specification of fpm for each virtual host of apache: [HOST=main.addepi.fr] open_basedir = "/data/admin/" doc_root = "/data/admin/web" mail.log = "/data/admin/app/logs/php.mail.error.log" short_open_tag = 1 error_log = "/data/admin/app/logs/php.error.log" default_charset = "utf-8" and some other package

javascript stop buffering when tab is inactive.

var $div = $ ( 'div' ); var a = 0 ; setInterval ( function () { a ++; $div . stop ( true , true ). css ( "left" , a ); }, 1000 / 30 ); Inactive browser tabs buffer some of the  setInterval  or  setTimeout  functions. stop(true,true)  will stop all buffered events and execute immediatly only the last animation. The  window.setTimeout()  method now clamps to send no more than one timeout per second in inactive tabs. In addition, it now clamps nested timeouts to the smallest value allowed by the HTML5 specification: 4 ms (instead of the 10 ms it used to clamp to) from:  http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome?answertab=active#tab-top

wait something loaded befero execute a acript.

waitForJ = function(fn, attemptsLeft) { var tick = attemptsLeft || 30; if (typeof(updatePhoneNew) == 'undefined' ) { //_gaq isn't registered yet if (tick > 1) { //recurse setTimeout(function() { waitForJ(fn, tick - 1); }, 100); } else { //no ticks left, log error console.log('failed to load window.gaq'); } } else { //gaq is loaded, fire fn fn(); } }; waitForJ(function() { //here's all my code... $J( '#phone_link' ).trigger('click'); }); this script can be used on vivastreet to show the phone number automatically by chrome extension.

add a custom loger filer

services: my_logger: class: Monolog\Logger arguments: [my_info] calls: - [pushHandler, [@my_log_handler]] my_log_handler: class: Monolog\Handler\StreamHandler arguments: [%kernel.root_dir%/logs/my_info.log, 100] Usage (in  Controller , for example): $this->get('my_logger')->info('info message');

remove html tag in string.

An obvious simple solution is to run strip_tags() over it, but that would simply remove tags and leave all text content intact, including embedded javascript and CSS, as well as all text inside elements that are normally hidden (e.g. by setting display: none on them). You could try some regex magic to filter out the parts you're not interested in, but regular expressions on HTML are generally a bad idea for anything nontrivial. The ultimate solution is, I'm afraid, to use a proper HTML parser and then pull the actual text out of the resulting DOM tree - by the time you have that, you'll be pretty close to implementing a web browser. form: http://stackoverflow.com/questions/5572469/get-html-output-cleaned-text-with-php

jquery get tag type

Getting the element type the jQuery way: var elementType = $(this).prev().prop('tagName'); Checking for specific element type: var is_element_input = $(this).is("input"); //true or false then you can do this: if ($('#myiframe').is('iframe')) $("#myiframe").contents().find("#myContent")

php array function

a good explaination for array_merge, +. array_push http://www.java-samples.com/showtutorial.php?tutorialid=997 You want to combine two arrays into one. Use  array_merge( ) : $garden = array_merge($fruits, $vegetables); The  array_merge( )  function works with both predefined arrays and arrays defined in place using array( ) : $p_languages = array('Perl', 'PHP'); $p_languages = array_merge($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Perl [2] => Python ) Accordingly, merged arrays can be either preexisting arrays, as with  $p_languages , or anonymous arrays, as with  array('Python') . You can't use  array_push() , because PHP won't automatically flatten out the array into series of independent variables, and you'll end up with a nested array. Thus: array_push($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Pe

include css in ie8

According to  this  bug report on the jquery site, there may well be a problem in IE8 with appending css files to the dom that contain relative links. The poster of the bug suggests that adding it as follows may work: var style = document . createElement ( "link" ); style . setAttribute ( "type" , "text/css" ); style . setAttribute ( "rel" , "stylesheet" ); style . setAttribute ( "href" , "xxx.css" ); jQuery ( "head" )[ 0 ]. appendChild ( style ); Or that using an absolute url may also work: $ ( ' ' ). appendTo ( 'head' ); ​ Although he goes on to say that any files included through @import within the appended css file will also not load as expected. I would suggest giving these test cases a whirl to see what loads for you and what doesn't (if it works you should get a grey background in the HTML window): Method Used in OP's question: 

change apache password file:

http://httpd.apache.org/docs/2.2/programs/htpasswd.html htpasswd  htpasswd  [ - c  ] [ - m  ] [ - D  ]  passwdfile   username htpasswd  - b  [ - c  ] [ - m  | - d  | - p  | - s  ] [ - D  ]  passwdfile   username   password htpasswd  - n  [ - m  | - d  | - s  | - p  ]  username htpasswd  - nb  [ - m  | - d  | - s  | - p  ]  username   password htpasswd /usr/local/etc/apache/.htpasswd-users jsmith Adds or modifies the password for user  jsmith . The user is prompted for the password. The password will be encrypted using the modified Apache MD5 algorithm. If the file does not exist,  htpasswd  will do nothing except return an error. htpasswd -c /home/doe/public_html/.htpasswd jane Creates a new file and stores a record in it for user  jane . The user is prompted for the password. If the file exists and cannot be read, or cannot be written, it is not altered and  htpasswd  will display a message and return an error status. htpasswd -db /usr/web/.htpasswd-al