Tuesday, September 20, 2011

Symfony: Merge embedded Form (Update)

Symfony provides a nice feature called "embedded Forms" (sfForm::embedForm) to embed subforms into a parent form. This can be used to edit multiple records at the same time. So let's say you have a basic user table called 'sf_guard_user' and a profile table called 'user_profile', then you might follow this guide to merge these forms together:

lib/forms/doctrine/sfUserGuardAdminForm.php:

 class sfGuardUserAdminForm extends BasesfGuardUserAdminForm {   public function configure()   {     parent::configure();      // Embed UserProfileForm into sfGuardUserAdminForm     $profileForm = new UserProfileForm($this->object->Profile);     unset($profileForm['id'], $profileForm['sf_guard_user_id']);     $this->embedForm("profile"$profileForm);   }2 }  

Remember to add "profile" to the list of visible columns inapps/backend/modules/sfGuardUser/config/generator.yml as decribed in the linked guide. The result may look like this:

Embedded form in symfony

This does what it is expected to do, but it doesn't look very nice. Especially for 1:1 related tables I'm more interested in a solution that looks like this:

Merged forms in Symfony

You can reach this using sfForm::mergeForm, but sadly the merged model won't get updated and you'll run into problems if the forms are sharing fieldnames. The solution is the following method embedMergeForm which can be defined in BaseFormDoctrine to be avaible in all other forms:

lib/forms/doctrine/BaseFormDoctrine.php:

 abstract class BaseFormDoctrine extends sfFormDoctrine {   /**    * Embeds a form like "mergeForm" does, but will still    * save the input data.    */   public function embedMergeForm($namesfForm $form)   {     // This starts like sfForm::embedForm     $name = (string) $name;     if (true === $this->isBound() || true === $form->isBound())     {       throw new LogicException('A bound form cannot be merged');     }     $this->embeddedForms[$name] = $form;      $form = clone $form;     unset($form[self::$CSRFFieldName]);      // But now, copy each widget instead of the while form into the current     // form. Each widget ist named "formname|fieldname".     foreach ($form->getWidgetSchema()->getFields() as $field => $widget)     {       $widgetName "$name|$field";       if (isset($this->widgetSchema[$widgetName]))       {         throw new LogicException("The forms cannot be merged. A field name '$widgetName' already exists.");       }        $this->widgetSchema[$widgetName] = $widget;                           // Copy widget       $this->validatorSchema[$widgetName] = $form->validatorSchema[$field]; // Copy schema       $this->setDefault($widgetName$form->getDefault($field));            // Copy default value        if (!$widget->getLabel())       {         // Re-create label if not set (otherwise it would be named 'ucfirst($widgetName)')         $label $form->getWidgetSchema()->getFormFormatter()->generateLabelName($field);         $this->getWidgetSchema()->setLabel($widgetName$label);       }     }      // And this is like in sfForm::embedForm     $this->resetFormFields();   }    /**    * Override sfFormDoctrine to prepare the    * values: FORMNAME|FIELDNAME has to be transformed    * to FORMNAME[FIELDNAME]    */   public function updateObject($values null)   {     if (is_null($values))     {       $values $this->values;       foreach ($this->embeddedForms AS $name => $form)       {         foreach ($form AS $field => $f)         {           if (isset($values["$name|$field"]))           {             // Re-rename the form field and remove             // the original field             $values[$name][$field] = $values["$name|$field"];             unset($values["$name|$field"]);           }         }       }     }      // Give the request to the original method     parent::updateObject($values);   } }  

This method ensures that each fieldname is unique (named 'FORMNAME|FIELDNAME') and the subform is validated and saved. It is used like embedForm:

lib/forms/doctrine/sfUserGuardAdminForm.php:

 class sfGuardUserAdminForm extends BasesfGuardUserAdminForm {   public function configure()   {     parent::configure();      // Embed UserProfileForm into sfGuardUserAdminForm     // without looking like an embedded form     $profileForm = new UserProfileForm($this->object->Profile);     unset($profileForm['id'], $profileForm['sf_guard_user_id']);     $this->embedMergeForm("profile"$profileForm);   } }  

Feel free to use this method in your own project. Maybe this method get's merged into Symfony some day ;-)

Update
frostpearl reported a problem using embedFormMerge() in conjunction with the autocompleter widget from sfFormExtraPlugin. If you expire these problems try to replace all occurences of "$name|$field" with "$name-$field".

Let's Play with Symfony 1.2 and Doctrine

It's been quite a long time I didn't give a go to Doctrine, so as it's gonna be bundled by default in with the upcoming 1.2 release of symfony, I thought it was a good occasion to play with it.

So let's checkout the 1.2 SVN branch of symfony and create a test project with a main application[1]:

 $ mkdir sf12test && cd sf12test $ mkdir -p lib/vendor $ svn co http://svn.symfony-project.com/branches/1.2 lib/vendor/symfony $ php lib/vendor/symfony/data/bin/symfony generate:project sf12test $ ln -s ../lib/vendor/symfony/data/web/sf web/sf $ ./symfony generate:app main

Create a webserver vhost pointing to the web folder of the project directory. I've already explained plenty of times how to achieve this step.

Now, let's enable the sfDoctrinePlugin and disable the Propel one by editing the setup() method of theconfig/ProjectConfiguration.class.php file:

  php   public function setup()   {     $this->disablePlugins('sfPropelPlugin');     $this->enablePlugins('sfDoctrinePlugin');   } 

You can list the available tasks running this simple command:

 $ ./symfony list doctrine

Managing the Database Schema

First, configure your config/databases.yml file to set the database connection parameters. If you want to quick test Doctrine, use a local SQLite db, like this:

  yaml all:   doctrine:     class:    sfDoctrineDatabase     param:       dsn:    sqlite://<?php echo dirname(__FILE__).'/../data/data.db' ?> 

We're going to make a very simple weblog application, so let's configure our database schema. We can do it in YAML[2], so fire up your favorite editor/IDE and edit a brand new config/doctrine/schema.yml:

  yaml BlogPost:   actAs:     Sluggable:       fields:       [title]     Timestampable:   columns:     title:          string(255)     body:           clob     author:         string(255)  BlogComment:   actAs:            [Timestampable]   columns:     blog_post_id:   integer     author:         string(255)     email:          string(255)     content:        clob   relations:     BlogPost:       class:        BlogPost       local:        blog_post_id       foreign:      id       foreignType:  many       type:         one 

Note that Doctrine offers several pretty cool features including native behaviors (timestampable and slugable are used here).

Now, create a data/fixtures folder and put a data.yml file in, containing some test data in YAML format:

  yaml BlogPost:   p1:     title: My first post     body: |       This is cool.     author: NiKo     created_at: "<?php echo date('Y-m-d H:i:s', time() - 86400) ?>"   p2:     title: My second post     body: |       This is still cool.     author: NiKo     created_at: "<?php echo date('Y-m-d H:i:s', time() - 7200) ?>"   p3:     title: Third post     body: |       Is this one cool?     author: Roger Hanin     created_at: "<?php echo date('Y-m-d H:i:s') ?>"  BlogComment:   c1:     BlogPost: p3     author: John     email: john@doe.com     content: Hey, you're right there.     created_at: "<?php echo date('Y-m-d H:i:s', time() - 86400) ?>"   c2:     BlogPost: p3     author: Paul     email: paul@doe.com     content: Nope, he's not.     created_at: "<?php echo date('Y-m-d H:i:s') ?>" 

Okay, now run the command below to generate the needed files, create the database and fill it with the data fixtures:

 $ ./symfony doctrine:build-all-load

We can run several DQL queries in command line to check if everything is fine. DQL is very powerful, and compatible with a lot of RDBMS. You'll find more information on DQL on the doctrine website.

For example, to find all blog posts:

 $ ./symfony doctrine:dql "From BlogPost p" found 3 results -   id: '21'   title: 'My first post'   body: "This is cool.\n"   author: NiKo   slug: my-first-post   created_at: '2008-10-29 15:14:25'   updated_at: '2008-10-30 15:14:25' -   id: '22'   title: 'My second post'   body: "This is still cool.\n"   author: NiKo   slug: my-second-post   created_at: '2008-10-30 13:14:25'   updated_at: '2008-10-30 15:14:25' -   id: '23'   title: 'Third post'   body: "Is this one cool?\n"   author: 'Roger Hanin'   slug: third-post   created_at: '2008-10-30 15:14:25'   updated_at: '2008-10-30 15:14:25' 

Another example, to find informations about the blog post with slug third-post and its associated comments:

 $ ./symfony doctrine:dql "Select p.title, p.author, c.author, c.content From BlogPost p, p.BlogComment c Where p.slug = 'third-post' Group by c.id" found 3 results -   id: '23'   title: 'Third post'   author: 'Roger Hanin'   BlogComment: [{ id: '15', author: John, content: 'Hey, you''re right there.' }, { id: '16', author: Paul, content: 'Nope, he''s not.' }] 

Put the Query Logic in the Model

The Model part of any MVC architecture must contains the business data and associated logic. In other words, these data and logic should never be handled anywhere else, to decouple your components at max. So we'll add some query methods in thelib/model/doctrine/BlogPostTable.class.php file, which represents our blog_post table and available operations on it:

  php <?php class BlogPostTable extends Doctrine_Table {   public function getAll()   {     return Doctrine_Query::create()->       select('p.title, p.slug, p.body, p.author, p.created_at, count(c.id) numcomments')->       from('BlogPost p, p.BlogComment c')->       orderBy('p.created_at DESC')->       groupBy('p.id')->       execute();   }    public function getOneBySlug($slug)   {     $posts = Doctrine_Query::create()->       from('BlogPost p')->       leftJoin('p.BlogComment c')->       where('p.slug = ?')->       orderBy('c.created_at ASC')->       limit(1)->       execute(array($slug));      return isset($posts[0]) ? $posts[0] : null;   } } 

A Weblog is About Web Interface, uh?

Okay, let's add pretty controllers and templates to give some life to our blog. First, generate a post module in the main app:

 $ ./symfony generate:module main post

Then, edit the apps/main/modules/post/actions/actions.class.php file:

  php <?php class postActions extends sfActions {   public function executeIndex($request)   {     $this->posts = Doctrine::getTable('BlogPost')->getAll();   }      public function executeShow($request)   {     $this->post = Doctrine::getTable('BlogPost')->getOneBySlug($slug = $request->getParameter('slug'));     $this->forward404Unless($this->post, 'No post with slug=' . $slug);     $this->comments = $this->post->getBlogComment();   } } 

We should have display templates too. The first one will show the posts list, inapps/main/modules/post/templates/indexSuccess.php:

  php <?php foreach ($posts as $post): ?>   <?php include_partial('post/post', array('post' => $post, 'numComments' => $post->getNumcomments())) ?>   <hr/> <?php endforeach; ?> 

Note that we must create the _post partial template, in apps/main/modules/post/templates/_post.php:

  php <h2><?php echo link_to($post->getTitle(), 'post/show?slug='.$post->getSlug()) ?></h2> <p>   <small>Posted by <?php echo $post->getAuthor() ?> on <?php echo $post->getCreatedAt() ?>   <?php if (isset($numComments)): ?>     - <?php echo $numComments ?> comments   <?php endif; ?>   </small> </p> <?php echo $post->getBody(ESC_RAW) ?> 

The other main template will display one post and its comments, in apps/main/modules/post/templates/showSuccess.php:

  php <?php include_partial('post/post', array('post' => $post)) ?>  <h2>Comments</h2> <?php if (!count($comments)): ?>   <p>No comment yet.</p> <?php else: ?> <?php foreach ($comments as $comment): ?>   <p><small>By <?php echo $comment->getAuthor() ?> on <?php echo $comment->getCreatedAt() ?></small></p>   <blockquote><?php echo $comment->getContent() ?></blockquote> <?php endforeach; ?> <?php endif; ?> 

That's it. A rough but functional weblog if you lauch your browser to yourhost/main_dev.php/post/index:

step2.png

And if you click a post title:

step1.png

Good News, the Forms Framework Works with Doctrine Too

Symfony 1.1 introduced the new forms framework, and good news, Doctrine can take part of it. So maybe you've already noticed it, we have form classes generated already, in the lib/form/doctrine folder of the project.

So let's add a neat commenting system to our blog, by first editing the lib/form/doctrine/BlogCommentForm.class.php file:

  php <?php class BlogCommentForm extends BaseBlogCommentForm {   public function configure()   {     unset($this['id'], $this['created_at'], $this['updated_at']);          $this->widgetSchema['blog_post_id'] = new sfWidgetFormInputHidden();          $this->validatorSchema['author']  = new sfValidatorString(array('min_length' => 3));     $this->validatorSchema['email']   = new sfValidatorEmail();     $this->validatorSchema['content'] = new sfValidatorString(array('min_length' => 5));   } } 

Now, use the form in the executeShow() method of our controller:

  php <?php // ...   public function executeShow($request)   {     $this->post = Doctrine::getTable('BlogPost')->getOneBySlug($slug = $request->getParameter('slug'));     $this->forward404Unless($this->post, 'No post with slug=' . $slug);     $this->comments = $this->post->getBlogComment();          $comment = new BlogComment();     $comment->setBlogPost($this->post);     $this->form = new BlogCommentForm($comment);          if ($request->isMethod('post') && $this->form->bindAndSave($request->getParameter('blog_comment')))     {       $this->redirect('post/show?slug='.$this->post->getSlug());     }   } 

And in the showSuccess.php template, we'll append the form display:

  php <h3>Add a comment</h3>  <?php echo $form->renderFormTag(url_for('post/show?slug='.$post->getSlug())) ?>   <table>     <?php echo $form ?>     <tr>       <td></td><td><input type="submit"/></td>     </tr>   </table> </form> 

We've now a pretty commeting system added to our blog, thanks to all the goodness provided by symfony and Doctrine:

step3.png

Conclusion

The time when everyone choosed Propel because it was more stable than Doctrine seems to be over. Doctrine is robust, and performs quite well on my box. Furthermore, it handles complex relationships and dynamic object hydratation natively and better than Propel. Doctrine is also very well integrated into symfony, certainly because Jonathan Wage - the Doctrine lead developer - now works for Sensio, creator and main sponsor of symfony.

Wednesday, August 10, 2011

symfony bridge wordpress, share cookie for domain and subdomain, Sharing cookies among all subdomains

There's a common problem of sharing cookies for domain and subdomain.
solution is set domain with www.example.com and set cookie domain to '.example.com'
reference: 


Sharing cookies among all subdomains


As explained earlier, cookies are not shared among subdomains or between the domain
and the subdomain. In order to set cookies accessible by all subdomains, use the 
following techniques:

  1. While writing the cookie, set the cookie domain to ".domain.ext" so that it applies 
    to all subdomains.

  2. If the cookie domain is set to ".domain.ext", it will not be accessible by a user
    who types in the address without the www before the domain (i.e. http://domain.ext).
    Therefore, redirect all requests without www to http://www.domain.ext.


There are some reported problems with the above approach. It is safe to set the default cookie 
with no domain specified and then set another one with domain as ".domain.ext". In this case 
there is no need for the redirects.
However, remember that session cookies are set by the web server software and you may not
have control over how the cookie domain is set.

real world case:

symfony site on example.com
blog is wordpress on blog.example.com
both sharing same top navigation, so, in blog, the login/logout link should be switched by user current status.
to achieve this, in blog.example.com , we need to know if user has logged in at example.com

steps:

1, set permanent redirect, redirect all example.com request to www.example.com

2, in sfGuardSecurityUser class, add

    // set a cookie for all subdomains
    sfContext::getInstance()->getResponse()->setCookie('wp_bridge', $this->generateRandomKey(), time() + $expiration_age, '/', '.example.com');

at bottom of signIn method

  add

sfContext::getInstance()->getResponse()->setCookie('wp_bridge', '', time() - $expiration_age, '/', '.example.com');

at bottom of signOut method


3, in wordpress

in my case, find the file : wp-content/themes/mytheme/custom/custome_functions.php

find cookie by

echo 'Hello '.($_COOKIE['wp_bridge']!='' ? $_COOKIE['wp_bridge'] : 'Guest');



DONE, enjoy the bridge.

Monday, August 08, 2011

Friday, May 13, 2011

网上问诊单

     首先声明,如有以下十一种人之一者请不要填写:

1、不信中�的人 .

2、���有疑�的人 .

3、自以�是的人 , 又要吃西�又要吃中�的人 .

4、懂一���中� , ����方指指��的人 .

5、拿到�方 , 不按�吃的人 .

6、拿到�方 , 到了�房抓� , ����此方太� , ��不行 , 要加那��等 , 立刻就�定不拿�了 , 或回������方�� , 此�笨蛋不要治 , �於��草型 , 完全不知道自己在作什� . ��不是�� , 他干���治� , �也信 , �在有�笨拙 .

7、不���建�的人 , 以�吃�就好了 , 比如: 肝硬化是由喝酒引起 , 吃中�後 , 仍然不戒酒 , 如何�好呢?

8、重��同一��的人 , 表示他不相信你了 . 不可治 . (我在看病�都ㄧ定��解�病情�病人�, 但是再次���病人居然�� , 吃��是�什�? 你��不�人 , 不相信就不要�看中� , 何必如此害自己呢?)

9、一有重病 , 只要人�什�好 , 就立刻去做 , �果�吃一大堆� , 此�有疾病�投�的人不要治 .

10、平�吃一大推不必要的�或�他命的人 , 生病��看�� , �身��一�囊 , ��求����何�可吃 , 何�不可吃 , ��人除了本身疾病外 , 又自己增添�多本�根本不存在的����生 , 千�不要看 .

11、吃药有效 , 不坚�吃的人

以上十一�人 , 奉�所有中�� , 千�不要去治 , 此�病人你就算是治好也不�感�你 , 他���你是蒙到的 , 治不好就都是你的� , �不�去���什�自己�得到此病 , �人�什��有此病 , 只�怪�生不好 . 但是如果他�是去看西�� , �度就一百八十度��了 , 完全�西�的� , 就像一�口袋中的�物一� , 主人�食什�就吃什� , 乖巧的要死 , 就算�果是死於西�之手 , 他�也不�去怪罪西� , 家����在抬病患��出院� , 列�向西�致�意的 ..

中医网上诊病,失去了四诊的望、闻、切三诊,为准确诊断,有效治疗,请问病患者详细填写下面内容(连同注意、说明全部复制,以便查阅),有则选择,无则删除。

1、请详细填写下列条目——

性别:

生辰:(公元)年月日时

籍贯: 

婚否:

职业:

身高:

体重: 

腰围:

肤色:

主要症状:

发病经过:

治疗经过(尽量详细一点):

西医病名:

是否长期用过激素:

是否大量用过消炎药:

是否做过内脏手术:

2、请选择下列部位身体状态(将所无状态删除)——

脉(左:快,慢,有力,无力,粗,细,浮,沉,松,紧,停顿,时快时慢)

(右:快,慢,有力,无力,粗,细,浮,沉,松,紧,停顿,时快时慢)

面(红,黄,白,黑,青):

眼(瞳仁色灰;白睛色青,色黄;有血丝,有瘀斑,有隆起,有黑点,眼下色青,眼皮肿):

舌(肥大,瘦,尖红,滑湿,有齿痕,干,苔腻,黄苔,白苔,中有裂纹,舌下筋脉曲张):

齿(整齐,龃龉,有缝,颜色,大,长,齿痛,活动,有斑,无力)

耳(鸣,聋,痒,痛,流水,左,右):

目(干涩,昏花,眩晕,流泪,痛,痒,左,右):

口(苦,干,酸,无味,溃疡,流涎):

鼻(不通,流涕,凉,热,左孔,右孔):

咽(干,痛,痒,吞咽困难):

胸(满,闷,胀,痛,骨痛,热,凉):

乳(胀,痛,增生,肿块,左,右):

胁(胀,痛,热,凉,左,右):

腹(胀,满,痛,肿,硬):

外阴(肿,胀,痛,热,凉,如烧,坠胀,挛缩):

心(烦,悸,慌,紧,痛,凉,热,跳快):

心下(满,闷,堵,胀,烧):

胃(胀,痛,满,酸,凉,热):

头(痛,晕,麻,木,昏,沉重):

项(僵,痛,酸重,不能转动):

肩(痛,凝,沉重,萎缩,凉,热,左,右):

臂(痛,麻,木,胀,酸,颤,凉,热,左,右):

手(凉,热,干,出汗,麻,颤,指痛,甲痛,萎缩,左,右):

背(痛,酸,重,胀,凉,热,左,右):

腰(酸,重,痛,胀,凉,热,左,右,中间):

腿(痛,酸,重,麻,木,肿,胀,僵,软,凉,热,左,右,内侧,外侧):

膝(痛,肿,凉,热,软,骨痛,无力,左,右):

足(痛,胀,麻,木,软,凉,热,左,右):

跟(痛,凉,热,麻,胀,左,右):

足趾(麻,痛,胀,凉,热,左,右,部位):

3、请选择与下列项目对应的身体状况(必选)——

饮(多,少,喜凉,喜热,喜温,喜酸,喜辣,喜苦,喜咸,喜甜):

食(多,少,喜米,喜面,喜粥,喜油腻,厌油腻):

睡眠(多,少,失眠,多睡,多梦,易醒):

大便(干,湿,粘,便秘,失禁,色黑,色黄,色白,溏泻,一日一次,一日数次,数日一次):

小便(多,少,不畅,不禁,色黄,色白,次数多,次数少):

房事(有,无,多,少,阳亢,阳痿,早泄,手淫,曾堕胎):

月经(先期,后期,多,少,暗,红,淡,浓稠,清稀,有血块,痛经,漏泻):

白带(有,无,多,少,白,黄,腥,臭):

4、请回答身体经常有如下哪些症状——

(发热,出汗,怕冷,怕风,怕热,哮,喘,咳,气短,有痰,打嗝,呕逆,恶心,腹泻,便血,尿血,吐血,鼻血,牙龈出血,烦躁,肢体震颤,肢体僵硬,乏力倦怠,头重脚轻,少气懒言,嗜卧,厌卧,半身不遂,时冷时热,长期低烧,淋巴节肿大,胸骨刺痛,站立觉累,静脉曲张,骨发空,骨发热,梦遗,早泄,阳痿,不孕)

5、七情何者为重——

(喜悦,愤怒,忧郁,思虑,悲伤,恐惧,惊悸)

如何知道你的身体是否健康,有以下五通标准。

饮食通:不偏食,有良好的嗅觉、味觉及食觉。口润不渴,亦可及时补充水分。

休息通:休息每日在七八个小时左右,午时有一小时的午睡时间,夜有梦但不多,睡眠深。醒后精力充沛。

大小便通:大小便正常,每日晨起有一次大便,不干不稀,通畅,五分钟可解决问题。小便清,无泡沫,无杂质。小便与饮水量成正比。

体力通:体力充沛,能够胜任一般劳动,不感到疲劳,过重体力劳动,半小时左右能休息过来

阳气通:身体温暧,手足温暧,身不畏寒,无上火现象,有正常的性能力。     

公布秘方,比一比,看谁的【生肌散】效果更好?(zhuanzai)

公布秘方,这是我用了十多年的生肌散,效果很好,公开给大家,欢迎各位拿秘方来比较效果高低!

人中白(炙)30g  象皮(砂炒泡)50g  乳香30g  滑石粉30g  血竭30g  白芨30g

共研细末,撒于创口处

主治:一切伤口、溃疡,久不愈合,效神速!


Thursday, May 05, 2011

肥胖的原因与减肥

    人体肥胖的原因,一是身体的垃圾不能及时清理,堆集在细胞和组织空隙,或与人体脂肪同处,垃圾和它所吸收的水分增加了人的体重,并使人的精神倦怠,气色黄浊。本质的原因则是年龄大或疾病造成的脏腑功能减弱,新成代谢不足及内分泌不调所引起;二是饮食不节,营养过剩,又因阳气不足,不能将多余的营养转化为动能,或转化为元精收藏(纳气归肾或曰潜阳)。反而使之化为脂肪存贮于人体组织间隙或体内空处。

减肥的方法一般有节食、运动和药物治疗等。节食对营养过剩引起的肥胖有一定作用,但对新成代谢不足或内分泌不调引起的肥胖效果不佳,且节食不能太过,否则影响人体的正常能量供给;运动有助于过剩营养的消耗并排除一些体内垃圾,但运动同时也促进代谢垃圾的产生,人如果阳气不足,运动消耗的阳气不能及时恢复和补充,运动增加的垃圾不能及时排除,反而使身体更差而益增肥胖。所以运动减肥只能针对内体较好而缺乏运动的人。但不管运动或节食,都很辛苦,大多数人都不能坚持,而且坚持了也不一定见效,所以人们更期望药物减肥。目前,国内外药物减肥的方法很多。一是厌食法,服用一些药物,让人不想吃东西,产生减肥的作用。肥是减了但对人身体的破坏很大,可谓本未倒置,得不偿失。且一旦不服药,肥胖又会回来。二是脱水法或曰排毒法。即服用具有泄泻作用的药物,使人增加排泄而减重。实际上只是排水,即减去了人体细胞和组织包括垃圾与脂肪的水分,毒(拉圾)和脂肪并没少,却会造成人正常生理需要的水分也不能满足,而影响了人的身体健康。停药后,垃圾与脂肪的水分得到补充,重量又回来了。且因人的身体变弱,会产生更多的垃圾和脂肪,人的体重迅速反弹,并将逐渐超过服药之前。

    正确的减肥方法只有一种,即保护和提升人体的阳气(即元气)。人体的阳气增加后,排毒(垃圾)功能和利用营养能力增强,产生和积聚的垃圾与脂肪少,并能排除积存的体内垃圾和燃烧利用体内脂肪,故能减肥。现代人普遍阳气不足。原因包括:夜生活过度,饮酒过度,纵情过度,焦虑过大,喜食冷饮,动辄服用清热药物和抗生素(寒性)等等。只有尽量克服以上毛病,才能保护好自身阳气。提升人体阳气的方法有:1、内体好而运动少的人可选择运动减肥(运动可增加人的阳气水平)。2、药物调节人体功能,扶助阳气,使清气能升,浊气能降。药方:

    党参15克、白术15克、干姜15克、甘草10克、肉桂8克、山楂肉15克。煎汤服用。(因病引起的肥胖,当先解决病根,再谈减肥。)

    服药后出现头晕,身酸无力,排便增加等等不舒服状,都是正常的。是在排垃圾,排完就好了。到时你发现你很容易的就这样减了肥,没有付作用不说,而且还美了容,健了身。感到身轻体健、饮食有味、睡眠加深、气色变好、工作精力增强、心情倍加愉悦。

    赞曰:莫道减肥难,岐路千万般;一旦方法对,玉环变飞燕。 

    补充说明:本减肥方可以长期吃,有双向调节的作用,可使胖者变瘦,瘦者变胖;有肥减肥,无肥强身。开始时排浅层毒素,减肥速度较快。但过后一段时间,可能反而会有增加体重或体积的现象,但不必惊奇,这是深层垃圾吸收水分造成的。继续吃药,垃圾就会排出,从而达到真正减肥而不反弹的目的。

Wednesday, April 27, 2011

办公室养生之――松肩(脾胃虚弱,面色晦暗者请进)


办公室养生之——松肩(脾胃虚弱,面色晦暗者请进)
  
   
  
  不经常运动的人,特别是办公室工作人员,因为用电脑的缘故,双肩容易紧张而不能松沉,乃至影响到颈椎和整个后背,好像背着重物。从外表看来,这类人双肩习惯性上耸,即所谓的“架肩”,长此下去脾胃之气容易积滞,进而面色苍白,四肢瘦弱,抑或是虚胖,体力不佳,从中医角度来看,这些均是脾胃虚弱,气机壅滞所导致的。因为双肩为中焦气血流通的要津,明代李�的《医学入门》中保养导引的方法中“开关法”和“起脾法”均是用松肩的方法以调理脾胃之气。一般人上肢用力往往力量锁在肩关节而透不到双手,但是传统锻炼方法则要求松肩,力量在肩关节不停留直接贯通到双手,如太极拳、形意拳、八卦掌等均有如此要求。下面为大家介绍一种锻炼双肩的方法,打通肩部的滞涩,恢复气血流通。
  
   
  
  1预备式:坐在椅子上或放松站立均可,两手交叉抱胸。
  
  2 摇肩:左右转圈摇摆,肘尖的轨迹呈“∞”字形,大约100次。
  
  3 转肩:两手自然下垂,手指自然伸直,肩膀用力由后向前转圈(后—上—前—下—后);之后由前向后转圈,各100次。要领:动作缓慢柔和,手臂放松,垂直下坠,好像挂在肩膀上的钟摆一样,丝毫不着力。
  
  4 开肩:本动作是在走路过程中完成的,走路时双手随步伐前后摆动,像解放军叔叔的“齐步走”。手的摆动的水平高度在肚脐和胸之间,大约在中脘、上脘的位置。要领:步伐不要太快,要像散步一样放松,手臂像钟摆一样摆动,手指自然伸直,全身放松。
  
  以上动作1、2、3可连续做,每次大约半小时,适合于办公室工作人员疲劳时缓解压力,放松身心。动作4可在上下班走路时做,每次最好持续半小时。
  
   
  
  动作效应:
  
  锻炼一般在10分钟后就会感觉肩关节周围发热,30分钟后会感到整个背部包括颈椎,都会有温热的感觉,说明通过运动阳经气血通畅,颈椎、肩周、失眠、头痛等疾病会得到缓解。在做动作半小时后,手指会有温暖而柔软的感觉,说明手三阴经逐渐通畅,心、肺、脑血管疾病都会有所减轻。
  
  本方法简单,但是功效卓著,长期锻炼可以增进食欲,健壮脾胃,增强体格。我们看看为什么参过军的人体质都比一般人要好?他们面色红润、声音洪亮、精神面貌和体力都是非常棒!包括大学生军训,我的一个同班同学军训后连晕车都治好了。其中一个重要的原因,那就是天天齐步走,暗合妙道,松开双肩,脾胃之气调畅,中焦脾胃是后天之本,它一旦强壮,自然有病祛病无病强身了。晕车本是脾胃病,用这种方法治疗自然会收到良好的效果。
  
   
  
  小建议:办公室工作人员,精神压力比较大,工作长时期不活动,难免心情郁闷,进而影响脾胃功能,食欲不振,消化不良,面色萎黄,睡眠不香。遇到这种情况,您可以在饭前饭后、睡觉之前花十分钟做一下松肩,使气血运行通畅,如果持之以恒,食欲逐渐就会旺盛,睡眠自然就会香甜。

Friday, February 18, 2011

Unknown record property / related component "profile" on "sfGuardUser"

If you got this error:

500 | Internal Server Error | Doctrine_Record_UnknownPropertyException Unknown record property / related component "user" on "sfGuardUserProfile"

You are lucky, this error bothered me for a long time, but now you know the answer!

user_id in Profile must be interger(4)

the important part is (4)

if you don't have it in the schema, you will get the error above.

example:

sfGuardUserProfile:   columns:     user_id: {type: integer(4)}     email: {type: string(100), email: true}     favorite_color: {type: string(100)}   indexes:     user_id_fk_idx:       fields: [user_id]   relations:     User:       class: sfGuardUser       local: user_id       foreign: id       type: one       foreignType: one       foreignAlias: Profile


keywords:

symfony 1.4 sfGuardUser Profile sfDoctrineGuardPlugin


--
Kindest Regards,

Zhen Sun

Tuesday, November 16, 2010

李子暘:“通胀”这把火玩不得

诱导大量错误投资,周期性地制造出经济危机,导致社会财富的巨额浪费,甚至酿成政治危机,这才是通胀最大的社会危害。
  李子暘
  经济学者,铅笔经济研究社理事
  最近通胀的话题很热闹,但舆论中关于通胀的常识性谬误很多,这里只拣两个最重要的来说说。
  谬误一:要用CPI(消费者物价指数)来衡量是否有通胀,通胀有多少。
  这个说法的错误有两层。第一层:CPI是可任意制定的指数。CPI,是一些消费品的价格加总计算。这些商品价格上涨了,就说CPI上涨了,还会煞有介事地计算出是百分之几点几。这些商品价格没有上涨,就说CPI没变,没有通胀。显然,选择哪些商品列入CPI的清单,功夫很深。想掩盖通胀,只要选择那些价格很少或没有变化的商品。至于涨价很凶的商品,只要将其排除到CPI以外即可。比如房价,虽然是许多居民支出中的大头,但从来就不列入CPI。
  政府的第二招是:就算列入CPI的商品价格上涨,也可以通过价格管制来应对。CPI当然不会按照黑市价格来计算。因此,如果某商品被列入CPI清单,企业家投资时一定要谨慎。该商品的价格很可能会受到政府管制。投资的企业家,分分钟可能被政府和公众指为乱涨价的奸商,成为通胀的替罪羊。
  即使CPI的计算是完备和公正的,能如实反映商品和服务的价格变化,它也不是衡量通胀的好指标。
  通货膨胀,从字面含义和经济原理上看,都是指货币数量增加,并没有物价上涨的含义。无论物价是否上涨,只要流通中的货币量增加了,就发生了通胀。用物价是否上涨来衡量是否有通胀,就好像用是否得了高血压、糖尿病来衡量一个人是否需要减肥。不是所有的肥胖者都必定得了高血压、糖尿病,但肥胖者必定体重超标。有体重一个指标就够了。
  同样,衡量通胀是否存在,只需看货币量是否增加,而不能等到物价上涨再来谈论通胀。等到物价上涨,再设法抑制通胀,为时已晚。
  谬误二:通胀的危害是造成物价上涨。
  从政府决策层,到经济学家和公众,都对此深信不疑。相应的政策后果就是:如果通胀造成的物价上涨没有超出社会容忍度,那为了刺激经济增长,不妨玩玩通胀。
  甚至还有经济学家主张提高通胀的社会容忍度,简直是一派胡言!
  如果通胀增发的货币在瞬间到达每个人,那就只是币值改变而已,但通胀的真实过程不是这样的。
  通胀增发出来的货币,是通过某个入口进入经济体的。现在,主要是通过银行贷款这个入口。于是,有机会从银行贷款的人,就先拿到了货币。而挣工资的广大民众,则较晚拿到增发的货币,甚至根本拿不到。那些先拿到货币的人自然好处多多。他们就像是可以合法使用伪钞的人。通胀就是把别人的财富偷偷地转移到这些人手中。
  可见,通胀是在全社会范围内公然进行的掠夺和财富再分配,而且是从大众向少数人转移财富,使贫者愈贫,富者愈富。这是通胀真正的社会危害,远比物价上涨恶劣得多。
  除此之外,通胀往往通过政府人为压低利率进行。压低了利率,银行就可以发放更多的贷款,就会有更多的货币进入流通。对普通人来说,银行升降几个百分点的利率,影响不大。但对产业投资来说,那几个百分点的利率变化是很关键的。
  投资10亿的项目,利率升降1%,就意味着每年成本增减1000万。利率的高低,直接决定了这个项目是合算还是不合算。人为压低利率,许多原本不合算的项目就会变得合算。这些项目所需要的各种原料能源供应,还会诱使一大批上下游项目投资上马。
  但低于市场利率的低利率是不可持续的。增发的货币,经过一段时间,会通过各种渠道,流到更多的社会成员手中,推动物价的普遍上涨,并形成政治压力。
  政治压力之下,政府只能选择提高银行利率,减少贷款量,减少流通中的货币量。这时,两难局面就出现了。
  要么,继续实行通胀政策,结果是物价飞涨,甚至民不聊生;要么,停止通胀政策,结果是大量错误的投资暴露出来,许多企业破产,员工失业,这就是经济危机和经济萧条。
  诱导大量错误投资,周期性地制造出经济危机,导致社会财富的巨额浪费,甚至酿成政治危机,这才是通胀最大的社会危害。
  那些以为通胀只意味着物价上涨的人,认识不到通胀真正的危害,就像小孩子不懂火的厉害一样。于是,他们也就像小孩玩火一样玩通胀。形容他们处境的最好比喻就是:盲人骑瞎马,夜半临深渊。
  可叹的是,他们的愚蠢,将由全体社会成员负责。大声疾呼让他们立即停止玩火,难道不是我们必须要做的事情吗?

Saturday, September 11, 2010

custom form formatter/decorators

symfony 1.4 form

custom form formatter/decorators

class xxxForm extends BaseXxxForm
{
  public function configure()
  {
    $myDecorator = new myListFormDecorator($this->getWidgetSchema());
    $this->widgetSchema->addFormFormatter('custom', $myDecorator);
    $this->widgetSchema->setFormFormatterName('custom');
  }
}

class myListFormDecorator extends sfWidgetFormSchemaFormatter {
  protected
    $rowFormat = "
      %hidden_fields% %field% %help%
    ",
    $helpFormat = '<div class="help">%help%</div>',
    $errorRowFormat = "%error%",
    $errorListFormatInARow = " ",
    $errorRowFormatInARow = " ",
    $namedErrorRowFormatInARow = " ",
    $decoratorFormat = "%content%";
}// decorator class