Entries tagged as technique
终于用上左手的 Logitech V450 Nano Cordless Laser Mouse Tue, Sep 16. 2008
和谐四年秋,洒家弱冠六年纪念日当天,于京东购买赛普泰克——啊不,是罗技泰克无尾老鼠一只。
但是此鼠娘家罗技泰克所附送嫁妆 SetPoint 乃伪劣产品,不得博得洒家新欢 Microsoft Windows 2008 之欢心,2008 不认其名门出身,只当是一 HID compliant Mouse,真是狗眼看人低,微软看鼠卑啊。
SetPoint 迫东家 2008 的于淫威,亦不敢主仆相认,就是不敢显示出那欲说还羞的 My Mouse 选项卡。
借古狗洋大人之力,终于在无尾鼠娘家旁边的一个老爷们扎堆聊天的地方找到了前人留下的洋文名帖一张,将藩语译成我中华之文字,方懂上书意思是,喜新厌旧是罪过的,有了新老婆 2008,不能忘了二老婆 Vista 和小妾 XP,须到二老婆或者小妾房中寻得名为 CDDRV2 的仙丹一枚给新老婆服用才可解除新老婆的障眼之疾。
虽说此方甚好,可以药到病除,但是难为了吾等洁身自好,二老婆小妾皆无之人,难道为了这个还要纳上一房不成?未免荒谬。再看前述之帖,此洋鬼子上留蝇头小楷一行,曰,吾等清白之人之赤心,上可达天庭,故玉帝命他将仙丹藏于一个名为 RapidShare 之八卦炉内,以诚心猛击此链接即可得仙丹。
洒家于是踏上 NJU_BRAS 大道前去寻访仙丹,不曾想,好事多磨,玉帝说 BRAS 戴着不爽,遂令如来将 BRAS 大道缩成极小,以难为用 BRAS 取经之人。无奈之下,退回来继续用 PROXY 小道,道上无人阻碍,方能够到达藩国按洋鬼子之指点找到仙丹,取回,用 LDPINST.exe 做药引给新欢 2008 服下,之间电光火石之间,2008 立马认出洒家的无尾鼠出自罗技泰克名门,立即取名为 Logitech HID compliant Cordless mouse。此时寻到 SetPoint,SetPoint 一看婆家已经接纳此鼠,亦显现出 My Mouse 以和之。
至此,洒家魂牵梦绕之 My Mouse 终得拨云见日,吾等方能用上左手鼠标。善哉善哉。
附上洋泾兵之贴:Windows Server 2008 x86(32bit) + Setpoint 4.6 installation ,后来者请自去寻访仙丹。
一个 # 不够,那么就多来几个吧 Wed, Sep 3. 2008
网页中经常要做的一件事情就是让一个链接来执行一个 JavaScript 脚本,例如:< href="#" onClick="some_js_here();">Some text</a>,不过这样的副作用是因为有 href="#"。所以导致点击完后页面会滚动到最上面。
以前用的几种解决方案:
- 不写 href,这样会导致很多浏览器不会把 a 标签按照你预期的方式渲染;
- 在href 里面直接写 JavaScript 脚本,这样不完全符合 W3C 的规范。
其实要解决这个问题,不让浏览器把页面滚动到最上面,很简单,href="" 里面 多写几个 # 就行了,我一般用 6 个比较保险,这个方法适用于 IE5、IE6、IE7、FF2、FF3。虽然不知道为什么但是很好用。猜测是因为 # 表示进行页内书签的跳转,但是多个 # 浏览器就不知道什么意思了,干脆罢工好了,哈哈。
解决 propel-convert-xml-schema 把 null 默认值处理为字符串的问题 Thu, Aug 21. 2008
通过 propel-convert-xml-schema 把 xml schema 转化成 PHP 代码的时候,如果一个字符型字段不能为空且没有明确输入默认值,例如:
- <column name="username" type="VARCHAR" size="128" required="true" default=""/>
生成的 PHP 代码中该字段的默认值是 'null' 而不是 null,导致页面输入框的默认值不是空值,而是一个字符串的 null,很恼火。因为要么在页面中每个字段都对 'null' 做特殊处理,要么修改生成的 PHP 类文件,但是一旦重新执行 propel-convert-xml-schema 就会重新覆盖。
解决办法:修改 propel-generator/classes/propel/phing/PropelCreoleTransformTask.php 文件(对于 Symfony 来说,就是 symfony/vendor/propel-generator/classes/propel/phing/PropelCreoleTransformTask.php)。应用如下 patch:
- 507,510c507
- < //$node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue));
- < if(!empty($defValue)) {
- < $node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue));
- < }
- ---
- > $node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue));
参见:#2045 (propel-convert-xml-schema generate null text as default values) - symfony - Trac。
在 Symfony 中结合使用 Structures/DataGrid、sfSmartView、Propel Mon, Aug 18. 2008
今天需要在 symfony 中使用 datagrid 型控件对一个分页+排序的表格进行展示。但是 sfDataGrid 写得实在是太糟糕了,没有找到其他的比较好的 plugin。
PEAR 中的 Structures/DataGrid 倒是不错。但是两个问题:无法和现在偶使用的 sfSmartyView 直接结合,因为在 $datagrid->fill($smarty); 的时候,symfony 还没有生成 view instance,除非直接获取生成的 HTML_TABLE 或者类似的结果,这样不利于 MVC 的分离和对具体样式的控制;二是现有的 datasource 无法和 symfony 使用的 propel 直接结合,如果采用检索全部结果再传递给 Structures/DataGrid 进行分页处理,那么效率非常低下。
于是自己写一个 datasource,并且使用了一点技巧解决和 sfSmartyView 结合的问题。
Structures_DataGrid_DataSource_Propel 类的定义:
- class Structures_DataGrid_DataSource_Propel extends Structures_DataGrid_DataSource {
- protected $criteria = null;
- protected $con = null;
- protected $object = null;
- function __construct($object, $criteria, $con = null) {
- parent::Structures_DataGrid_DataSource();
- $this->object = new $object();
- $this->criteria = $criteria;
- $this->con = $con;
- }
- //TODO: this is not a good way, due to MySQL Bug #21787
- $this->criteria->setLimit(0);
- $this->criteria->setOffset(0);
- $result = $this->object->doCount($this->criteria);
- return $result;
- }
- case 'asc' :
- $this->criteria->addAscendingOrderByColumn($sortSpec);
- break;
- case 'desc' :
- $this->criteria->addDescendingOrderByColumn($sortSpec);
- break;
- default :
- return PEAR::raiseError("Sorting dir must be ASC or DESC!");
- }
- return true;
- }
- function fetch($offset = 0, $len = null) {
- $c = $this->criteria;
- $c->setOffset($offset);
- $c->setLimit($len);
- }
- $objects = $this->object->doSelect($c);
- foreach ($objects as $object) {
- $result[] = $object->toArray(BasePeer::TYPE_COLNAME);
- }
- return $result;
- }
- }
action 中的代码段:
- public function execute() {
- // get data source
- $c = new Criteria();
- $datasource = new Structures_DataGrid_DataSource_Propel('SysUiaAccountPeer', $c);
- // setup datagrid
- $datagrid = & new Structures_DataGrid(10);
- $datagrid->bindDataSource($datasource);
- SysUiaAccountPeer::USERNAME=>"DESC"
- ));
- $datagrid->addColumn(new Structures_DataGrid_Column('用户名', SysUiaAccountPeer::USERNAME, SysUiaAccountPeer::USERNAME, array (), ' ', ''));
- // add more columns here
- // use a tip to get output using smarty
- $smarty = $datagrid->setRenderer('smarty');
- // set pager params
- 'prevImg'=>"上一页", 'nextImg'=>"下一页", 'separator'=>"|", 'delta'=>"5", 'clearIfVoid'=>true, 'spacesBeforeSeparator'=>"1", 'spacesAfterSeparator'=>"1", 'firstPageText'=>'第一页', 'lastPageText'=>'最后页'
- ), $smarty);
- $this->dg = $datagrid->getOutput();
- $this->pager = $pager;
- return sfView::SUCCESS;
- }
模板中的处理:
- <!-- Build header -->
- {section name=col loop=$dg.columnSet}
- <th{$dg.columnSet[col].attributes}><!-- Check if the column is sortable -->
- {if $dg.columnSet[col].link != ""} <a href="{$dg.columnSet[col].link}">{$dg.columnSet[col].label}</a>
- <!-- Show the current ordering with an arrow --> {if
- $dg.columnSet[col].name == $smarty.request.orderBy} {if
- $smarty.request.direction == "ASC"}↑{elseif
- $smarty.request.direction == "DESC"}↓{/if} {/if} {else}
- {$dg.columnSet[col].label} {/if}</th>
- {/section}
- </tr>
- <!-- Build body -->
- {section name=row loop=$dg.recordSet}
- <tr {if $smarty.section.row.iteration is even}bgcolor="#EEEEEE"{/if}>
- {section name=col loop=$dg.recordSet[row]}
- <td{$columnSet[col].attributes}>{$dg.recordSet[row][col]}</td>
- {/section}
- </tr>
- {/section}
- <td colspan="...">{$pager}</td>
- </tr>
- </table>
MySQL 对于 COUNT(*) 和 LIMIT 同时使用的 BUG Sun, Aug 17. 2008
对一个有 29 条记录的表进行如下操作:
- SELECT COUNT( sys_uia_account.ID ) FROM sys_uia_account结果 29
- SELECT COUNT( sys_uia_account.ID ) FROM sys_uia_account LIMIT 10结果 29
- SELECT COUNT( sys_uia_account.ID ) FROM sys_uia_account LIMIT 10 , 10没有结果
看来以后使用 COUNT(*) 的时候不能同时使用 LIMIT offset, row_count 这种表达方式了。
PS:如果统计全表记录,使用下面的方法会更加快捷:
- SELECT SQL_CALC_FOUND_ROWS *
- FROM sys_uia_account;
- SELECT FOUND_ROWS( ) ;
唯一需要注意的就是,这两个查询必须在一起进行,因为 SQL_CALC_FOUND_ROWS 不对结果进行任何缓存。
