刚刚发现 Gmail 里开启了 auto complete (search suggests),以前还是 Labs 里的一项功能,我并没有启用。这下倒好,Gmail 自说自话启用了,关也关不掉。
Day: February 25, 2010
-
Better to custom Magento interface from base/default
Magento 官方推荐以 blank interface 为基础开发个性化的 interface。这说法没错,但有局限性。如果不熟悉 Magento interface 的构成,blank interface 确实一个很好的出发点,如”blank“的名称所言,它没有花里胡哨的背景影响你的构思,如果你是设计师,blank interface 给了你极大的方便。
但世上难有两全其美的事情——blank interface 方便了设计师,但不方便最终用户(我指后台用户)。设计是一时的,用户是一世的,所以我认为两者有冲突时应该更多地照顾用户。Magento interface 有三层 fall-back 机制,在 System > Configuration > Design 可以设置 theme 和 default theme,系统还有最底层的 fall-back to base/default。
设想一下,如果基于 blank interface 开发 my_wonderful_theme,那在后台只能设置 theme 为 “my_wonderful_theme”,设置 default theme 为 “blank”。同时,严格按照 Magento 的规范,只把 “blank” 中需要修改的文件拷贝到 “my_wonderful_theme” 中进行修改。最终 “my_wonderful_theme” 保存了一些修改文件。如果全站页面统一使用 “my_wonderful_theme”,则没有问题;可是,Magento 允许个别 cms, category 或 product page 使用不同的 theme,通常会是 “my_wonderful_theme” 局部的变种,这样就有问题了。假设需要对某个 category 下的页面使用 “my_fantastic_theme”,而 “my_fantastic_theme” 只是在“my_wonderful_theme” 基础上修改了 header 部分,但 “my_fantastic_theme” 无法就它所缺的文件 fall-back to “my_wonderful_theme”——很可惜,Magento 只提供了三层 fall-back 机制,假如它就多给一层 fall-back,那就没有我这篇文章了。
简言之,如果基于 blank interface 开发,那么 cms, category 或 product page 里的 custom design 功能就成了鸡肋。如果设计师/开发者交付一个基于 blank interface 的 theme 和若干变种,用户无法方便地完成切换,这就是个败笔。以后还是以 base/default interface 为起点开发吧,其实也很方便。
-
Lightbox not working in Magento 1.4 solved
My case is special –
很久以前为 Magento 1.3 加装 Lightbox 2 时,我听从某人的建议,去掉了 Magento 自带的 scriptaculous effects.js,安装了当时最新的 scriptaculous 1.8.3 effects.js。Lightbox 调试成功后一直没去动它。
Magento 升级到 1.4 后,默认启用 Merge JavaScript Files,这时 Lightbox 就不工作了。如果禁用 Merge JavaScript Files,Lightbox 恢复正常。我调试不出 Lightbox 失效的原因,大概是 js library 版本不兼容。再看了一下 Magento 如今自带 scriptaculous 1.8.2,估计和 1.8.3 相差不大,为了兼容性,干脆就用 Magento 原装的 js。
于是去掉我自装的 scriptaculous 1.8.3 effects.js,启用 Merge JavaScript Files,如我所愿 Lightbox 恢复正常。
-
Do not use is_null()
测试一个变量是否为 NULL,我曾喜欢用 is_null() 函数,现在发现还比如直接用 === 比较来得快。
php.net 上有人写了个测试,得出的结论是 === 比 is_null() 快30倍。
$v = NULL; $s = microtime(TRUE); for($i=0; $i<1000; $i++) { is_null($v); } print microtime(TRUE)-$s; print "<br>"; $s = microtime(TRUE); for($i=0; $i<1000; $i++) { $v===NULL; } print microtime(TRUE)-$s;
这是2007年的事情了,我不清楚他的环境配置。如今在我 Intel(R) Celeron(R) CPU 2.80GHz PC 充当的测试服务器上,running zend server php 5.2.9,得出的结论是 === 比 is_null() 快1-2倍。看来 php is_null() 的效率进步了不少,但还是慢。以后我得改用 NULL === $v 的方式了。
-
Magento theme improvements from 1.3 to 1.4
There are loads of improvements in the newest version of Magento themes. I just list some from my point of view. I observed these changes when I started using Magento 1.4 three days ago, but they may exist in the late version of 1.3.x.x already for long.
Everyone knows we should separate presentation from content. Magento does it very well since its first public version. Magento 1.4 just makes separation even better. A theme is about presentation, usually made of two parts, app/design and skin. Compared with skin, app/design part is somehow closer to content. Magento 1.4 themes remove layouts and templates from app/design, which means they are fully rely on css to present different themes. Base/default theme is an exception, but it is a fall-back theme.
In 2-column or 3-column page templates, main column code comes before left/right column. I think it hugely helps SEO. I first saw this kind layout in a Zen-Cart template. Maybe Magento was inspired by it. Under template/page, one-column.phtml was deleted, which saves confusion with 1column.phtml.
The header logo is no longer displayed as a background image, which is a minor change but makes big improvement.
I spent 3 days to re-write my theme to be compliant with Magento 1.4 but I love these changes.