Author Archives: yobol

symfony 模板外调用Helper

sfProjectConfiguration::getActive()->loadHelpers(array(“Text”));

Posted in symfony helper | Comments Off

symfony 调用不同app的routing

http://www.symfony-project.org/blog/2009/02/17/cross-application-links

Posted in routing | Comments Off

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

Posted in symfony 知识 | Comments Off

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

Posted in forms | Comments Off

symfony Doctrine link 添加一对多关联记录

例子: User(table) ———— id:~ —————— Book(table) ———— id:~ user_id(fk) —————— 添加一个user和他的藏书 1. $u=new User(); $u->name = ‘lag’ $u->save(); —————— $b=new Book(); $b->name = ‘lag book’; $b->save(); $b->link(‘User’,array($u['id'])); 2. $u=new User(); $u->name = ‘lag’; $u->Book[]->name = ‘lag book’; $u->save(); 3. $bookids … Continue reading

Posted in Doctrine | Comments Off

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值

Posted in forms | Comments Off

symfony 1.4 Doctrine formArray()数组作为表单保存

formArray()可以将一组数据作为form表单保存 $data = array( ‘name’ => ‘John’, ‘age’ => ’25′, ‘Emails’ => array( array(‘address’ => ‘john@mail.com’), array(‘address’ => ‘john@work.com’) ); $user = new User(); $user->fromArray($data); $user->save();

Posted in Doctrine | Comments Off

symfony 1.4 Doctrine toArray()

object->toArray($deep) $deep为true时,将关联数据也转换为数组 $user = $q->leftJoin(‘Books’)->where(…)->fetchOne(); $user->toArray(true) echo $user['name'] echo $user['Books']['id']

Posted in Doctrine, Uncategorized | Comments Off

symfony 1.4 Doctrine fetchOne返回数组

fetchOne($params,$hydrationMode);默认返回为对象,返回数组使用Doctrine::HYDRATE_ARRAY $user = $q->where(‘id=?’) ->fetchOne(array(1)) ->toArray(); 等同于: $user = $q->where(‘id=?’) ->fetchOne(array(1),Doctrine::HYDRATE_ARRAY); 等同于: $user = $q->where(‘id=?’,array(1)) ->setHydrationMode(Doctrine::HYDRATE_ARRAY) ->fetchoOne();

Posted in Doctrine, Uncategorized | Comments Off

添加多条记录,字段为空则不添加(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

Posted in Uncategorized, forms | Comments Off

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

Posted in Uncategorized, forms | Comments Off

生意人的素质标准[转]

我首先要说明的是做生意赚钱与做事业是两回事,我这里只说做小生意,就是普通人开个店、做个经销商、开个小贸易公司、白领辞职后开个小咨询公司等普通中国人的小生意;

Posted in Uncategorized | Comments Off

支持symfony框架的IDE NetBeans

支持symfony框架的IDE NetBeans

Posted in symfony 知识 | Comments Off

nginx日志分析解决方案

- Awstats 很多PHP搭建的网站都在由apache转向了nginx。nginx的日志信息如何分析呢? 当然你可以自己写一个,但是这里也推荐一款结果信息非常详尽的开源工具——Awstats ,它基于perl编写,它的介绍如下: AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible … Continue reading

Posted in Uncategorized | Comments Off

cygwin安装

http://www.programarts.com/cfree_ch/doc/help/UsingCF/CompilerSupport/Cygwin/Cygwin1.htm http://www.cygwin.com/ http://www.cygwin.cn/

Posted in Server | Comments Off

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

Posted in forms | Comments Off

mysql 查询一条记录的上一条和下一条记录

mysql 查询一条记录的上一条和下一条记录mysql 查询一条记录的上一条和下一条记录 Continue reading

Posted in mysql | Comments Off

mysql获得最后一条记录

select id from article where id= (select max(id) from article); mysql获得最后一条记录

Posted in mysql | Comments Off

symfony1.2数据库保存session

创建数据表sessions

Posted in Propel | Comments Off

图片验证扩展sfValidatorFileImage

http://snippets.symfony-project.org/snippet/343

Posted in symfony 知识 | Comments Off