上一篇文章里介绍了symfony的cheat sheet,但官方的下载地址貌似被墙,所以我也没有下载到全部的cheat sheet,不过还好bobhero那里有,虽然是1.0的,但很多内容依然很有用。
2009-10-27
2009-10-22
Cheat Sheets!
bobhero就喜欢搞一些稀奇古怪的东西,800块的古董式键盘买了两个外加一个超级怪异的轨迹球鼠标,智能手机买了两个一个打电话一个玩日历,Arch Linux装了Awesome然后接了两个显示器。早在两年之前,我刚来公司的时候,就对他的这些卡片很感兴趣。
这个东西的英文名叫cheat sheet,找了很久也没有找到一个合适的中文名,不过我觉得叫备忘卡很合适。从以往的工作上来看,cheatsheet的确帮了不少忙,最关键是省了翻手册的时间,网上有很多的cheat sheet,打印下来,塑封,然后放在电脑旁,下面是来自Added Bytes的cheat sheets。
| PHP (V1) | PHP (V2) | Mysql |
![]() |
![]() |
![]() |
| JavaScript | CSS (V1) | CSS (V2) |
![]() |
![]() |
![]() |
| mod_rewrite (V1) | mod_rewrite (V2) | HTML |
![]() |
![]() |
![]() |
| 正则表达式 (V1) | 正则表达式 (V2) | ASP/VBScript |
![]() |
![]() |
![]() |
| Python (V1) | Ruby on Rails | Subversion(SVN) |
![]() |
![]() |
![]() |
请访问 http://www.addedbytes.com/cheat-sheets/获取更多的CheatSheets.
注意:打印cheatsheet最好打印pdf版本的,图片格式的清晰度可能不是很好。忘了提醒大家了,塑封的时候可以把两张塑封到一起,比如PHP(V1)和PHP(V2)可以塑封个反正面。
下面这些是symfony官方提供的cheat sheets,貌似是1.0的,不过或多或少还有些用处。
| Symfony Admin Generator | Symfony Directory Structure And CLI |
![]() |
![]() |
请访问http://trac.symfony-project.org/wiki/CheatSheets来获取更多的symfony cheat sheets。下载链接我这里访问不了,不知道是删掉了还是被墙了,有新的发现我会再发出来。
2009-05-11
如何使用swift发送邮件
首先在项目的lib下建立vendor的文件夹
然后
svn checkout http://swiftmailer.svn.sourceforge.net/svnroot/swiftmailer/tags/php5/3.3.3/lib/ swift
接着把svn剪出的文件夹里的文件放到vendor目录下.
这样就可以使用swift发送邮件了
下面是一个简单的例子
<?php
try
{
// Create the mailer and message objects
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message('Mail\'s subject', $mailBody, 'text/html');
// Send
$mailer->send($message, $mailTo, $mailFrom);
$mailer->disconnect();
}
catch (Exception $e)
{
$mailer->disconnect();
// handle errors here
}
?>
2009-05-06
symfony1.2下的命令行程序(batch)
这里说的命令行程序就是在命令行(或者叫shell)下执行的程序, 因为我们多数时间是用浏览器来访问symfony程序的, 而有些时候, 我们也需要在shell下来执行我们的程序, 比如定时任务.
在网上一番搜索并没有找到相关内容, 在1.0的<The Definitive Guide To symfony>里提到了一个init-batch的命令, 但是这个命令在1.2中已经不存在了.
后来终于在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 Whether the task needs model initialization to access database (default: propel)
–brief-description A brief task description (appears in task list)描述:
The generate:task creates a new sfTask class based on the name passed as
argument:./symfony generate:task namespace:name
The namespaceNameTask.class.php skeleton task is created under the lib/task/
directory. Note that the namespace is optional.If you want to create the file in another directory (relative to the project
root folder), pass it in the –dir option. This directory will be created
if it does not already exist../symfony generate:task namespace:name –dir=plugins/myPlugin/lib/task
If you want the task to default to a connection other than propel, provide
the name of this connection with the –use-database option:./symfony generate:task namespace:name –use-database=main
The –use-database option can also be used to disable database
initialization in the generated task:./symfony generate:task namespace:name –use-database=false
You can also specify a description:
./symfony generate:task namespace:name –brief-description=”Does interesting things”
简单来说, 这个命令是用来创建命令行任务的, 我们来做一个简单的测试.
./symfony generate:task test
这样我们就生成了test命令, 我们可以象下面这样使用test命令
./symfony test
虽然什么也没有输出, 但是没有报错说明命令存在. 如果要给命令添加动作需要修改 /lib/task/testTask.class.php
我们写一个简单的例子
// add your code here
echo "it runing\n";
$users = UserPeer::doSelect(new Criteria);
echo count($users);
这段代码执行了数据库操作, 这说明在task中类都是自动在载的, 详细阅读testTask.class.php中的代码我们会发现task还支持很多功能, 设置参数, 命名空间等等.
(未完待续)
2009-04-08
symfony1.2的后台(generate-admin)模板结构
这里所指的后台模块是指由propel:generate-admin生成的后台管理模块,在symfony中可以自动生成一套强大的管理后台,并且可以订制或者重写模块中的动作或者模板,这里我们简单介绍一下模板的组成结构。
比如我们要给Test对象生成一套管理后台,那么我们使用命令
./symfony propel:generate-admin backend Test --module=test
然后我们访问backend/test, 这样你会看到一个自动生成的管理页面, 其程序在cache/app_name/env_name/modules/autoMudule/ 目录下. 我们这里主要分析模板目录templates, symfony1.2生成了以下的模板
indexSuccess.php # 列表页
_assets.php # 载入样式和脚本
_flashes.php # 消息框
_list_header.php # 页首
_list.php # 列表_list_td_stacked.php
_list_th_stacked.php
_list_th_tabular.php # 列标题
_list_td_batch_actions.php # 复选框
_list_td_tabular.php # 一条记录_list_field_boolean.php # boolean类型的表示方式
_list_td_actions.php # 对象操作
_list_batch_actions.php # 批量操作
_pagination.php # 分页条
_list_actions.php # 操作, 新建等
_filters.php # 过滤器_filters_field.php # 过滤器中的一项
_list_footer.php # 页尾
newSuccess.php # 新建页
editSuccess.php # 编辑页和新建页用了同一种结构_assets.php # 载入样式和脚本
_flashes.php # 消息框
_form.php # 表单_form_fieldset.php # 一组表单项
_form_field.php # 一个表单项
_form_actions.php # 操作, 提交, 取消等
_form_footer.php # 页尾
上面的缩进代表了调用关系, 为了更直观的表现出模板的结构, 做了下面两个图片
图1, 列表页的组成

图2, 新建和修改页的结构

本文完.




























