<?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>4's symfony blog &#187; batch</title>
	<atom:link href="http://www.foolbirds.com/t/batch/feed" rel="self" type="application/rss+xml" />
	<link>http://www.foolbirds.com</link>
	<description>all about symfony</description>
	<lastBuildDate>Tue, 17 Aug 2010 01:22:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>symfony1.2下的命令行程序(batch)</title>
		<link>http://www.foolbirds.com/batch-in-symfony12.html</link>
		<comments>http://www.foolbirds.com/batch-in-symfony12.html#comments</comments>
		<pubDate>Wed, 06 May 2009 07:09:15 +0000</pubDate>
		<dc:creator>maker</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://www.foolbirds.com/?p=745</guid>
		<description><![CDATA[这里说的命令行程序就是在命令行(或者叫shell)下执行的程序,　因为我们多数时间是用浏览器来访问symfony程序的,　而有些时候,　我们也需要在shell下来执行我们的程序,　比如定时任务.
在网上一番搜索并没有找到相关内容,　在１.０的&#60;The Definitive Guide To symfony&#62;里提到了一个init-batch的命令,　但是这个命令在１.２中已经不存在了.
后来终于在symfony命令中发现了generate:task命令,　这个命令的帮助文档是这样写的.
语法:
symfony generate:task [--dir="..."] [--use-database="..."] [--brief-description="..."] task_name
参数:
task_name            The task name (can contain namespace)
选项:
–dir                The directory to create the task in (default: lib/task)
–use-database     [...]]]></description>
			<content:encoded><![CDATA[<p>这里说的命令行程序就是在命令行(或者叫shell)下执行的程序,　因为我们多数时间是用浏览器来访问symfony程序的,　而有些时候,　我们也需要在shell下来执行我们的程序,　比如定时任务.</p>
<p>在网上一番搜索并没有找到相关内容,　在１.０的&lt;<a href="http://www.symfony-project.org/book/1_0/">The Definitive Guide To symfony</a>&gt;里提到了一个init-batch的命令,　但是这个命令在１.２中已经不存在了.</p>
<p>后来终于在symfony命令中发现了generate:task命令,　这个命令的帮助文档是这样写的.</p>
<blockquote><p>语法:<br />
symfony generate:task [--dir="..."] [--use-database="..."] [--brief-description="..."] task_name</p>
<p>参数:<br />
task_name            The task name (can contain namespace)</p>
<p>选项:<br />
–dir                The directory to create the task in (default: lib/task)<br />
–use-database       Whether the task needs model initialization to access database (default: propel)<br />
–brief-description  A brief task description (appears in task list)</p>
<p>描述:<br />
The generate:task creates a new sfTask class based on the name passed as<br />
argument:</p>
<p>./symfony generate:task namespace:name</p>
<p>The namespaceNameTask.class.php skeleton task is created under the lib/task/<br />
directory. Note that the namespace is optional.</p>
<p>If you want to create the file in another directory (relative to the project<br />
root folder), pass it in the –dir option. This directory will be created<br />
if it does not already exist.</p>
<p>./symfony generate:task namespace:name –dir=plugins/myPlugin/lib/task</p>
<p>If you want the task to default to a connection other than propel, provide<br />
the name of this connection with the –use-database option:</p>
<p>./symfony generate:task namespace:name –use-database=main</p>
<p>The –use-database option can also be used to disable database<br />
initialization in the generated task:</p>
<p>./symfony generate:task namespace:name –use-database=false</p>
<p>You can also specify a description:</p>
<p>./symfony generate:task namespace:name –brief-description=”Does interesting things”</p></blockquote>
<p>简单来说, 这个命令是用来创建命令行任务的, 我们来做一个简单的测试.</p>
<p><code>./symfony generate:task test</code></p>
<p>这样我们就生成了test命令, 我们可以象下面这样使用test命令</p>
<p><code>./symfony test</code></p>
<p>虽然什么也没有输出, 但是没有报错说明命令存在. 如果要给命令添加动作需要修改 /lib/task/testTask.class.php</p>
<p>我们写一个简单的例子</p>
<p><code>// add your code here<br />
echo "it runing\n";<br />
$users = UserPeer::doSelect(new Criteria);<br />
echo count($users);</code></p>
<p>这段代码执行了数据库操作, 这说明在task中类都是自动在载的, 详细阅读testTask.class.php中的代码我们会发现task还支持很多功能, 设置参数, 命名空间等等.</p>
<p>(未完待续)</p>
<ul class="related_post"><li><a href="http://www.foolbirds.com/use_symfony_filter_to_filteredurl.html" title="使用SYMFONY Filter 过滤URL">使用SYMFONY Filter 过滤URL</a></li><li><a href="http://www.foolbirds.com/%e4%bb%bfsymfony%e6%9c%ba%e5%88%b6%e5%ae%9e%e7%8e%b0%e4%b8%8d%e7%94%a8require%e6%88%96%e8%80%85include%e6%9d%a5%e5%ae%9e%e4%be%8b%e5%8c%96%e7%b1%bb.html" title="仿symfony机制实现不用require或者include来实例化类">仿symfony机制实现不用require或者include来实例化类</a></li><li><a href="http://www.foolbirds.com/use-datetime-in-php5-1-x-with-symfony.html" title="symfony1.4 DateTime对于PHP低版本的兼容问题">symfony1.4 DateTime对于PHP低版本的兼容问题</a></li><li><a href="http://www.foolbirds.com/%e5%a6%82%e4%bd%95%e5%9c%a8fixtures-yml%e5%86%99%e5%be%aa%e7%8e%af%e6%b7%bb%e5%8a%a0%e6%95%b0%e6%8d%ae.html" title="如何在fixtures.yml写循环添加数据">如何在fixtures.yml写循环添加数据</a></li><li><a href="http://www.foolbirds.com/symfony-1-4-database-utf8.html" title="symfony 1.4 数据库 utf8设置">symfony 1.4 数据库 utf8设置</a></li><li><a href="http://www.foolbirds.com/symfony-cheat-sheet.html" title="symfony cheat sheet">symfony cheat sheet</a></li><li><a href="http://www.foolbirds.com/cheat-sheets.html" title="Cheat Sheets!">Cheat Sheets!</a></li><li><a href="http://www.foolbirds.com/how-to-use-swift-to-send-mail-in-symfon.html" title="如何使用swift发送邮件">如何使用swift发送邮件</a></li><li><a href="http://www.foolbirds.com/generate-admin-templates-structure.html" title="symfony1.2的后台(generate-admin)模板结构">symfony1.2的后台(generate-admin)模板结构</a></li><li><a href="http://www.foolbirds.com/wideimage-in-symfony.html" title="在Symfony中使用第三方图片处理工具WideImage">在Symfony中使用第三方图片处理工具WideImage</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.foolbirds.com/batch-in-symfony12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
