
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>symfony 中文</title>
	<atom:link href="http://symfony.lag.cn/feed/" rel="self" type="application/rss+xml" />
	<link>http://symfony.lag.cn</link>
	<description>人人皆为吾师</description>
	<lastBuildDate>Wed, 04 Aug 2010 10:31:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>symfony 模板外调用Helper</title>
		<link>http://symfony.lag.cn/symfony-%e6%a8%a1%e6%9d%bf%e5%a4%96%e8%b0%83%e7%94%a8helper/</link>
		<comments>http://symfony.lag.cn/symfony-%e6%a8%a1%e6%9d%bf%e5%a4%96%e8%b0%83%e7%94%a8helper/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 10:31:12 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[symfony helper]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/?p=591</guid>
		<description><![CDATA[sfProjectConfiguration::getActive()->loadHelpers(array(“Text”));]]></description>
			<content:encoded><![CDATA[<p>sfProjectConfiguration::getActive()->loadHelpers(array(“Text”));</p>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-%e6%a8%a1%e6%9d%bf%e5%a4%96%e8%b0%83%e7%94%a8helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 调用不同app的routing</title>
		<link>http://symfony.lag.cn/symfony-%e8%b0%83%e7%94%a8%e4%b8%8d%e5%90%8capp%e7%9a%84routing/</link>
		<comments>http://symfony.lag.cn/symfony-%e8%b0%83%e7%94%a8%e4%b8%8d%e5%90%8capp%e7%9a%84routing/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 15:15:09 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[routing]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-%e8%b0%83%e7%94%a8%e4%b8%8d%e5%90%8capp%e7%9a%84routing/</guid>
		<description><![CDATA[http://www.symfony-project.org/blog/2009/02/17/cross-application-links]]></description>
			<content:encoded><![CDATA[<p>http://www.symfony-project.org/blog/2009/02/17/cross-application-links</p>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-%e8%b0%83%e7%94%a8%e4%b8%8d%e5%90%8capp%e7%9a%84routing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 中文等匹配 sfValidatorRegex()</title>
		<link>http://symfony.lag.cn/symfony-%e4%b8%ad%e6%96%87%e7%ad%89%e5%8c%b9%e9%85%8d-sfvalidatorregex/</link>
		<comments>http://symfony.lag.cn/symfony-%e4%b8%ad%e6%96%87%e7%ad%89%e5%8c%b9%e9%85%8d-sfvalidatorregex/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 07:44:07 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[symfony 知识]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-%e4%b8%ad%e6%96%87%e7%ad%89%e5%8c%b9%e9%85%8d-sfvalidatorregex/</guid>
		<description><![CDATA[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复制了个 &#8216;お &#8216;, 也不得行.. 然后把范围扩大到^[\u2E80-\u9FFF]+$, 这样倒是都通过了, 这个应该就是匹配中日韩文字的正则表达式了, 包括我們臺灣省還在盲目使用的繁體中文 而关于中文的正则表达式, 应该是^[\u4E00-\u9FFF]+$, 和论坛里常被人提起的^[\u4E00-\u9FA5]+$很接近 需要注意的是论坛里说的 ^[\u4E00-\u9FA5]+$这是专门用于匹配简体中文的正则表达式, 实际上繁体字也在里面, 我用测试器测试了下 &#8216;中華人民共和國 &#8216;, 也通过了, &#8230; <a href="http://symfony.lag.cn/symfony-%e4%b8%ad%e6%96%87%e7%ad%89%e5%8c%b9%e9%85%8d-sfvalidatorregex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre>
new sfValidatorRegex(
array(
'pattern' => '/^[^\W]?[a-zA-Z0-9\x{4e00}-\x{9fa5}_\s]*[^\W]?$/u'),
array(
'invalid'=>'昵称包含限制字符，请使用中文、英文和数字',
)
</pre>
<p>以下为转的：<br />
2E80～33FFh：中日韩符号区。收容康熙字典部首、中日韩辅助部首、注音符号、日本假名、韩文音符，中日韩的符号、标点、带圈或带括符文数字、月份，以及日本的假名组合、单位、年号、月份、日期、时间等。<br />
3400～4DFFh：中日韩认同表意文字扩充A区，总计收容6,582个中日韩汉字。<br />
4E00～9FFFh：中日韩认同表意文字区，总计收容20,902个中日韩汉字。<br />
A000～A4FFh：彝族文字区，收容中国南方彝族文字和字根。<br />
AC00～D7FFh：韩文拼音组合字区，收容以韩文音符拼成的文字。<br />
F900～FAFFh：中日韩兼容表意文字区，总计收容302个中日韩汉字。<br />
FB00～FFFDh：文字表现形式区，收容组合拉丁文字、希伯来文、阿拉伯文、中日韩直式标点、小符号、半角符号、全角符号等。<br />
比如需要匹配所有中日韩非符号字符,那么正则表达式应该是^[\u3400-\u9FFF]+$<br />
理论上没错,   可是我到msn.co.ko随便复制了个韩文下来,   发现根本不对,   诡异<br />
再到msn.co.jp复制了个 &#8216;お &#8216;,   也不得行..<br />
然后把范围扩大到^[\u2E80-\u9FFF]+$,   这样倒是都通过了,   这个应该就是匹配中日韩文字的正则表达式了,   包括我們臺灣省還在盲目使用的繁體中文<br />
而关于中文的正则表达式,   应该是^[\u4E00-\u9FFF]+$,   和论坛里常被人提起的^[\u4E00-\u9FA5]+$很接近<br />
需要注意的是论坛里说的 ^[\u4E00-\u9FA5]+$这是专门用于匹配简体中文的正则表达式,   实际上繁体字也在里面,   我用测试器测试了下 &#8216;中華人民共和國 &#8216;,   也通过了,   当然,   ^[\u4E00-\u9FFF]+$也是一样的结果 </p>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-%e4%b8%ad%e6%96%87%e7%ad%89%e5%8c%b9%e9%85%8d-sfvalidatorregex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 1.4 embedForm 保存2次问题</title>
		<link>http://symfony.lag.cn/symfony-14-embedform-%e4%bf%9d%e5%ad%982%e6%ac%a1%e9%97%ae%e9%a2%98/</link>
		<comments>http://symfony.lag.cn/symfony-14-embedform-%e4%bf%9d%e5%ad%982%e6%ac%a1%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 09:51:18 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-14-embedform-%e4%bf%9d%e5%ad%982%e6%ac%a1%e9%97%ae%e9%a2%98/</guid>
		<description><![CDATA[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(); &#8230; <a href="http://symfony.lag.cn/symfony-14-embedform-%e4%bf%9d%e5%ad%982%e6%ac%a1%e9%97%ae%e9%a2%98/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>使用embed会出现insert 2次的问题</p>
<pre>
configure(){
embedRelation('<em>ForwardProfile</em>');
}
function addProfile(){
//embed a new form
$profiles = new sfForm();
      $profile = new ForwardProfile();
      $profile->setForward($this->getObject());
      $profile_form = new ForwardProfileForm($profile);
      $profiles->embedForm('0',$profile_form);
      $this->embedForm('<em>ForwardProfile</em>',$profiles);
}
function bind(){
$this->addProfile();
}
</pre>
<p>这时会出现插入2条记录的情况，将关联名称<em>&#8216;ForwardProfile</em>改为其它名字可以解决</p>
<pre>
....
function addProfile(){
//embed a new form
...
      $this->embedForm('<em><strong>Fp</strong></em>',$profiles);
}
....
</pre>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-14-embedform-%e4%bf%9d%e5%ad%982%e6%ac%a1%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony Doctrine link 添加一对多关联记录</title>
		<link>http://symfony.lag.cn/symfony-doctrine-link-%e5%85%b3%e8%81%94%e8%a1%a8/</link>
		<comments>http://symfony.lag.cn/symfony-doctrine-link-%e5%85%b3%e8%81%94%e8%a1%a8/#comments</comments>
		<pubDate>Mon, 24 May 2010 07:22:06 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[Doctrine]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-doctrine-link-%e5%85%b3%e8%81%94%e8%a1%a8/</guid>
		<description><![CDATA[例子： User(table) &#8212;&#8212;&#8212;&#8212; id:~ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Book(table) &#8212;&#8212;&#8212;&#8212; id:~ user_id(fk) &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 添加一个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 &#8230; <a href="http://symfony.lag.cn/symfony-doctrine-link-%e5%85%b3%e8%81%94%e8%a1%a8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p> 例子：</p>
<p>User(table)<br />
&#8212;&#8212;&#8212;&#8212;<br />
id:~<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Book(table)<br />
&#8212;&#8212;&#8212;&#8212;<br />
id:~<br />
user_id(fk)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>添加一个user和他的藏书<br />
1.</p>
<pre>
$u=new User();
$u->name = 'lag'
$u->save();
------------------
$b=new Book();
$b->name = 'lag book';
$b->save();
$b->link('User',array($u['id']));
</pre>
<p>2.</p>
<pre>
$u=new User();
$u->name = 'lag';
$u->Book[]->name = 'lag book';
$u->save();
</pre>
<p>3.</p>
<pre>
$bookids = array();
$b1= new Book();
$b1->name = 'book1';
$b1->save();
$bookids[]=$b1['id'];

$b2= new Book();
$b2->name = 'book2';
$b2->save();
$bookids[]=$b2['id'];

$u=new User();
$u->name = 'lag'
$u->save();

$u->link('Book',$bookids);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-doctrine-link-%e5%85%b3%e8%81%94%e8%a1%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 关联id必须unset才会自动添加</title>
		<link>http://symfony.lag.cn/symfony-%e5%85%b3%e8%81%94id%e5%bf%85%e9%a1%bbunset%e6%89%8d%e4%bc%9a%e8%87%aa%e5%8a%a8%e6%b7%bb%e5%8a%a0/</link>
		<comments>http://symfony.lag.cn/symfony-%e5%85%b3%e8%81%94id%e5%bf%85%e9%a1%bbunset%e6%89%8d%e4%bc%9a%e8%87%aa%e5%8a%a8%e6%b7%bb%e5%8a%a0/#comments</comments>
		<pubDate>Thu, 20 May 2010 14:35:09 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-%e5%85%b3%e8%81%94id%e5%bf%85%e9%a1%bbunset%e6%89%8d%e4%bc%9a%e8%87%aa%e5%8a%a8%e6%b7%bb%e5%8a%a0/</guid>
		<description><![CDATA[数据库结构2个表： user ---------- id name ---------- book ---------- id user_id(fk) name ---------- bookForm.class.php的configure()设置 unset($this['user_id']); 这样embedForm后，user_id值自动添加为user的id值]]></description>
			<content:encoded><![CDATA[<pre>
数据库结构2个表：
user
----------
id
name
----------

book
----------
id
user_id(fk)
name
----------
</pre>
<p>bookForm.class.php的configure()设置</p>
<pre>
unset($this['user_id']);
</pre>
<p>这样embedForm后，user_id值自动添加为user的id值</p>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-%e5%85%b3%e8%81%94id%e5%bf%85%e9%a1%bbunset%e6%89%8d%e4%bc%9a%e8%87%aa%e5%8a%a8%e6%b7%bb%e5%8a%a0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 1.4 Doctrine formArray()数组作为表单保存</title>
		<link>http://symfony.lag.cn/symfony-14-doctrine-formarray%e6%95%b0%e7%bb%84%e4%bd%9c%e4%b8%ba%e8%a1%a8%e5%8d%95%e4%bf%9d%e5%ad%98/</link>
		<comments>http://symfony.lag.cn/symfony-14-doctrine-formarray%e6%95%b0%e7%bb%84%e4%bd%9c%e4%b8%ba%e8%a1%a8%e5%8d%95%e4%bf%9d%e5%ad%98/#comments</comments>
		<pubDate>Tue, 18 May 2010 07:07:15 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[Doctrine]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-14-doctrine-formarray%e6%95%b0%e7%bb%84%e4%bd%9c%e4%b8%ba%e8%a1%a8%e5%8d%95%e4%bf%9d%e5%ad%98/</guid>
		<description><![CDATA[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();]]></description>
			<content:encoded><![CDATA[<p>formArray()可以将一组数据作为form表单保存</p>
<pre>
$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();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-14-doctrine-formarray%e6%95%b0%e7%bb%84%e4%bd%9c%e4%b8%ba%e8%a1%a8%e5%8d%95%e4%bf%9d%e5%ad%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 1.4 Doctrine toArray()</title>
		<link>http://symfony.lag.cn/symfony-14-doctrine-toarray/</link>
		<comments>http://symfony.lag.cn/symfony-14-doctrine-toarray/#comments</comments>
		<pubDate>Tue, 18 May 2010 06:59:32 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-14-doctrine-toarray/</guid>
		<description><![CDATA[object->toArray($deep) $deep为true时，将关联数据也转换为数组 $user = $q->leftJoin('Books')->where(...)->fetchOne(); $user->toArray(true) echo $user['name'] echo $user['Books']['id']]]></description>
			<content:encoded><![CDATA[<p>object->toArray($deep)<br />
$deep为true时，将关联数据也转换为数组</p>
<pre>
$user = $q->leftJoin('Books')->where(...)->fetchOne();
$user->toArray(true)

echo $user['name']
echo $user['Books']['id']
</pre>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-14-doctrine-toarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 1.4 Doctrine fetchOne返回数组</title>
		<link>http://symfony.lag.cn/symfony-14-fetchone%e8%bf%94%e5%9b%9e%e6%95%b0%e7%bb%84/</link>
		<comments>http://symfony.lag.cn/symfony-14-fetchone%e8%bf%94%e5%9b%9e%e6%95%b0%e7%bb%84/#comments</comments>
		<pubDate>Tue, 18 May 2010 06:54:19 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/symfony-14-fetchone%e8%bf%94%e5%9b%9e%e6%95%b0%e7%bb%84/</guid>
		<description><![CDATA[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();]]></description>
			<content:encoded><![CDATA[<p>fetchOne($params,$hydrationMode);默认返回为对象，返回数组使用Doctrine::HYDRATE_ARRAY</p>
<pre>
$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();
</pre>
<pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/symfony-14-fetchone%e8%bf%94%e5%9b%9e%e6%95%b0%e7%bb%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>添加多条记录，字段为空则不添加（bind）</title>
		<link>http://symfony.lag.cn/%e6%b7%bb%e5%8a%a0%e5%a4%9a%e6%9d%a1%e8%ae%b0%e5%bd%95%ef%bc%8c%e5%ad%97%e6%ae%b5%e4%b8%ba%e7%a9%ba%e5%88%99%e4%b8%8d%e6%b7%bb%e5%8a%a0%ef%bc%88bind%ef%bc%89/</link>
		<comments>http://symfony.lag.cn/%e6%b7%bb%e5%8a%a0%e5%a4%9a%e6%9d%a1%e8%ae%b0%e5%bd%95%ef%bc%8c%e5%ad%97%e6%ae%b5%e4%b8%ba%e7%a9%ba%e5%88%99%e4%b8%8d%e6%b7%bb%e5%8a%a0%ef%bc%88bind%ef%bc%89/#comments</comments>
		<pubDate>Tue, 18 May 2010 05:36:48 +0000</pubDate>
		<dc:creator>yobol</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://symfony.lag.cn/%e6%b7%bb%e5%8a%a0%e5%a4%9a%e6%9d%a1%e8%ae%b0%e5%bd%95%ef%bc%8c%e5%ad%97%e6%ae%b5%e4%b8%ba%e7%a9%ba%e5%88%99%e4%b8%8d%e6%b7%bb%e5%8a%a0%ef%bc%88bind%ef%bc%89/</guid>
		<description><![CDATA[目的： 用户自定义数目的记录，有内容的input则插入数据库，没内容则忽略 例子： 已经embed的字段要用unset()才不会插入数据库 /lib/.../xxForm.class.php ... public function addNewTargets($number) { $targets = new sfForm(); for($i=0;$i&#60;$number;$i++) { $target = new WeightTarget(); $target-&#62;setWeightWatcher($this-&#62;getObject()); $target_from = new WeightTargetForm($target); $targets-&#62;embedForm($i, $target_from); } $this-&#62;embedForm('new', $targets); } public function bind(array $taintedValues = null, array $taintedFiles = &#8230; <a href="http://symfony.lag.cn/%e6%b7%bb%e5%8a%a0%e5%a4%9a%e6%9d%a1%e8%ae%b0%e5%bd%95%ef%bc%8c%e5%ad%97%e6%ae%b5%e4%b8%ba%e7%a9%ba%e5%88%99%e4%b8%8d%e6%b7%bb%e5%8a%a0%ef%bc%88bind%ef%bc%89/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>目的：<br />
用户自定义数目的记录，有内容的input则插入数据库，没内容则忽略<br />
例子：<br />
<img class="alignnone size-full wp-image-566" title="1" src="http://symfony.lag.cn/wp-content/uploads/2010/05/1.jpg" alt="1" width="545" height="183" /></p>
<p>已经embed的字段要用unset()才不会插入数据库</p>
<pre>/lib/.../xxForm.class.php
...
public function addNewTargets($number) {
        $targets = new sfForm();
        for($i=0;$i&lt;$number;$i++) {
            $target = new WeightTarget();
            $target-&gt;setWeightWatcher($this-&gt;getObject());
            $target_from = new WeightTargetForm($target);
            $targets-&gt;embedForm($i, $target_from);
        }
        $this-&gt;embedForm('new', $targets);
    }
  public function bind(array $taintedValues = null, array $taintedFiles = null){
    $new_targets = new sfForm();
    $taintedValues['user_simple_id'] = sfContext::getInstance()-&gt;getUser()-&gt;getGuardUser()-&gt;getId();
    foreach($taintedValues['new'] as $key =&gt; $new_target){

      if(!empty ($new_target['title'])){
          $target = new WeightTarget();
          $target-&gt;setWeightWatcher($this-&gt;getObject());
          $target_form = new WeightTargetForm($target);
          $new_targets-&gt;embedForm($key,$target_form);
      }else{ //字段为空则unset()
          unset ($taintedValues['new'][$key]);
      }
    }

    $this-&gt;embedForm('new',$new_targets);
    }
    parent::bind($taintedValues, $taintedFiles);
  }

#.apps/.../actions.class.php
public function executeNew(sfWebRequest $request)
  {
    $this-&gt;number = 5;#显示5条执行事项
    $this-&gt;form = new WeightWatcherForm();
    $this-&gt;form-&gt;addNewTargets($this-&gt;number);
  }</pre>
<pre>#template
...
&lt;?php include_partial('addTargets', array('form'=&gt;$form,'number'=&gt;$number))?&gt;
...</pre>
<p> </p>
<p>#partial<br />
&lt;?php for($i=0;$i&lt;$number;$i++):?&gt;<br />
&lt;tr&gt;<br />
    &lt;th scope=&#8221;row&#8221;&gt;&lt;?php if($i&lt;9) echo &#8217;0&#8242;.($i+1); else echo $i+1;?&gt;.&lt;/th&gt;<br />
    &lt;td&gt;<br />
        &lt;?php echo $form['new'][$i]['title']-&gt;render(array(&#8216;class&#8217;=&gt;&#8217;target_list&#8217;))?&gt;<br />
    &lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;?php endfor;?&gt;</p>
</pre>
<p>如果提交create时发现有非法字段，我们会发现提示错误。因为现在的记录数已经不是5条。所以我们要重新设置记录数：</p>
<pre>...
public function executeCreate(sfWebRequest $request)
  {
$post = $request-&gt;getPostParameters();

    $this-&gt;number = count($post['weight_watcher']['new']);#显示5条执行事项
    $this-&gt;form = new WeightWatcherForm();
    $this-&gt;form-&gt;addNewTargets($this-&gt;number);
...
}
...</pre>
<p>就ok了。</p>
]]></content:encoded>
			<wfw:commentRss>http://symfony.lag.cn/%e6%b7%bb%e5%8a%a0%e5%a4%9a%e6%9d%a1%e8%ae%b0%e5%bd%95%ef%bc%8c%e5%ad%97%e6%ae%b5%e4%b8%ba%e7%a9%ba%e5%88%99%e4%b8%8d%e6%b7%bb%e5%8a%a0%ef%bc%88bind%ef%bc%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
