Author: 芳草苑主

  • DtDdWrapper in Zend Framework

    我尝试着用 Zend Framework 重写了一个程序。在 Zend_Form 上徘徊了好久,研读了 Programmer’s Reference Guide N 遍,还是没有融会贯通。比如说,我想去掉默认的DtDdWrapper,用

    $element->removeDecorator(‘DtDdWrapper’);

    只对某些element起作用,对 Zend_Form_Element_Text 怎么也不起作用,最后发现用

    $element->removeDecorator(‘HtmlTag’);

    倒可行。

    问题是解决了,但还是没摸清 Zend Framework 设计思路。很累。

    续:

    其实,用$element->removeDecorator(‘HtmlTag’); 问题并没有完全解决。后来我用

    var_dump($element->getDecorators());

    查看了默认加载的装饰器以及装饰器的参数,发现对于 Zend_Form_Element_Text 来说,它的 dt 和 dd 并不是由 DtDdWrapper 加载的,事实上 Zend_Form_Element_Text 默认不加载 DtDdWrapper,难怪

    $element->removeDecorator(‘DtDdWrapper’);

    是不起作用的。

    那么,Zend_Form_Element_Text 的 dt 和 dd 是哪里来的呢?我仔细看了 var_dump 的结果,发现

    • dt 是由默认的 Label 装饰器默认的 dt 参数带来的
    • dd 是由默认的 ViewHelper 装饰器默认的 dd 参数带来的

    如果想要 Zend_Form_Element_Text 不套用 dt 和 dd,应该对症下药,修改 Label 和 ViewHelper 默认参数。

    上次用 $element->removeDecorator(‘HtmlTag’); 并没有去除 dt 和 dd,只是误打误撞让页面呈现出视同没有 dt 和 dd 时的效果。

  • Generate a UTF-8 encoded Actinic site

    I don’t like the way of Actinic tackle the problem. For example, if the web server set default charset as UTF-8, it will cause page rendering issue for Actinic. Especially for the pound sign. All the support knowledge from Actinic is redirecting people set the server using default chareset as ISO-8859-1. Then, my question is – why should I use ISO-8859-1 while UTF-8 has far better applicability, especially for multi-national sites?

    Nevertheless, can Actinic generate an UTF-8 encoded site? The answer is yes and no.

    Yes is because I have already achieved it; No is because Actinic can not make it happen for you (at least I won’t know how to control it), so you must do something outside Actinic. Here below is my detailed steps.

    • First, rewrite all requests to actinic generated files to index.php.
    • Second, create a bootscript, name it as index.php. This idea is inspired by Zend Framework. Make sure:
      1. The bootscript should be in utf-8 encode.
      2. The bootscript should be able to include actinic generate files according to request uri.
    • Third, in actinic templates, change meta tag charset to utf-8.
    • Last, at web server, adddefaultcharset utf-8.

    The most tricky part is actinic upload its files in iso-8859-1 encoding, but bootscript is utf-8 encoded. A normal include or require by php will not render pound sign correctly. I use output buffer to hack the problem.

    <?php
    ...
    ob_start();
    include($actinic);
    $utf8out = utf8_encode(ob_get_contents());
    ob_end_clean();
    echo $utf8out;
    ?>
    
  • Zend Framework lack of datagrid component

    Zend Framework is evolving quickly. Some while ago, it did not have Zend_Paginator, but now it’s there. But a component of paginator is enough for me. I want something like Zend_Datagrid. It’s not there yet.

    pao.fresco has developed Datagrid for Zend Framework. It looks good, but I am not confident using unofficial code.

    Magento also implement its own datagrid, but I do not know how to utilise as part of code outside of Magento.

  • Magento needs more features of ajax

    I can not blame Magento for its slow. It is such a big system aim to fit in all sectors of business. After all, after optimisation, Magento can achieve a decent speed on a entry level of server. However, I think Magento developers should bring more features of ajax into Magento. Fore example, when adding a product to compare, Magento give a success message “Product brah brah successfully added to compare list”. Magento currently reload the page to show the message. It is absolutely not necessary. Why not use ajax?

  • How to evaluate stock value

    我在思考一个财务上的问题:

    Euro-bags 公司每月初做一次库存盘点。1月初库存盘点,其中产品无纺布袋100箱,当时的生产成本为 £21/箱。库存盘点后,公司陆续生产了三批同型号产品无纺布袋,每批的数量和生产成本分别是

    • 200箱,£22/箱
    • 300箱,£20/箱
    • 200箱,£23/箱

    1月份,公司销售了550箱,理论上库存为250箱。但2月初,库存盘点显示无纺布袋260箱(理论库存与实际库存不一致的情况经常发生,否则也没必要作库存盘点)。

    问:

    • 2月初库存报告中的无纺布袋价值是多少?
    • 建议采用什么模型确定库存商品的单价?是统一单价,还是区别单价?
    • 统一单价的话,应用先进先出呢还是后进先出?
    • 区别单价的话,损益的数量该如何定价?
  • Obama and firefox

    我很难理解某位编辑的逻辑。他的一篇文章,介绍 Firefox 的新功能,却从奥巴马任命 Vivek Kundra 为 CTO of US goverment 开始说起,然后又用奥巴马结尾。

    奥巴马成为美国历史上首位黑人总统,这次惊动了整个世界的美国总统竞选,已经在长达一年多的时间里给人们的观念带来了冲击和改变!而给你的电脑换装,使用开源浏览器Firefox(火狐),这一点点改变不仅意味着你已经采取了支持开源软件的行动,更意味着你开始接受开源的观念!

    奥巴马和 Firefox 有联系吗?太牵强了。

  • From Apache to Nginx

    我感觉配置 nginx 渐入佳境了。配置 nginx 时应该用不同 apache 的思维,最主要的不同点是:

    apache 是 fallback 式配置,比如有两个 <directory> block,分别是 mydirectory 和 mydirectory/subdir。mydirectory/subdir 可以重写 mydirectory 的 directives,但 mydirectory/subdir 没有提到的 directives 就沿袭 mydirectory 的 directives。

    nginx 是 parallel 式配置,location 只能按优先规则取其一。

    另外,我觉得有人批评 apache 层层检测 .htaccess 造成效率低下的一个原因。我感觉这种说法并不妥,很多 apache 发行版默认 allowoverride none,用户只要根据需要在确实需要启用 .htaccess 的那一层启用 allowoverride,这并不造成效率损失,反而带来配置的灵活性。当然,nginx 不需要这种灵活性,因为它不是面向 share hosting 的产品。

    除了内存占用大是 apache 的硬伤,其他 nginx 的优势并不明显,apache 同样可以优化配置达到相应的效果,尽管很多配置不是 apache 的默认配置。(这只是我的总体感觉,我并没有深入去比较,欢迎探讨。)

  • eu domain transfer

    最近被 Lycos.co.uk 搞得够呛。它突然洗手不干了,估计是因为经济危机的关系。一个不想继续经营的公司服务质量是无法保证的,而且连个 complain 的地方都没有!

    我用到 lycos 的地方并不多,但还是在域名转移上有点麻烦。有几个 eu 域名委托 lycos 注册时,lycos 把联系人邮箱填为我的 lycos id,这个 id 已经无效了。而我一直认为 eu 域名转出需要原注册商的配合,所以反复请求 lycos 支持,而 lycos 爱理不理。事实上并不需要 lycos 配合。现在无暇去研究这个转移模式是否合理,能转成功已经谢天谢地了。

    以转到 godaddy 为例,godaddy 称之为四部曲:

    1. Initiate
    2. Authorize
    3. Accept/Decline
    4. Completion

    前两步几乎是同时完成的,只要在 godaddy 账户里点点鼠标就可以,第三步比较关键,但 godaddy 说

    The transfer is waiting for the customer to accept it at the losing registrar. If the customer does not accept the transfer at the losing registrar within 5 days, the transfer will be accepted automatically.

    这么说默认是 Accept 。如此很好,只要等上 5 天,域名就到 godaddy 账户项下了。

  • nginx has no path_info

    ngnix 0.6.35 没有实现 path_info。不知道 nginx 开发者是疏忽了,还是觉得没必要在 http server 层实现 path_info。我印象中有很多 php 程序的运行都依赖 $_SERVER[‘PATH_INFO’],所以在 ngnix proxy pass 给 php-cgi 之前,必须设置好正确的 path_info 参数。

    我认为最好的办法还是用正则表达式在 $fastcgi_script_name 里隔离出 script_name 和 path_info,但这样计算出的 path_info 用起来不如 ngnix variable 方便,而且得在脚本的安装位置或扩展名确定时才能写出相应的正则表达式。我是 nginx 新手,在 path_info 上折腾了三天才总结出一个相对满意的方案。如果 nginx 能给我一个 in-built variable $path_info,那会省事很多。

    当然我并不想责怪 nginx(apache 已经够令人称赞了,nginx 能超越它实属不易),说不定 nginx 不搞 path_info 有它的道理。 既然这样,php 编程时就应该考虑到 path_info 是不可靠的。以前我不太注意环境参数的获得性,如今审视了一下,除了 $_SERVER[‘PATH_INFO’]以外,$_SERVER[’PHP_SELF’] 和 $_SERVER[’SCRIPT_NAME’] 也是不可靠的。

    $_SERVER[‘REQUEST_URI’] 和 $_SERVER[’SCRIPT_FILENAME’] 相对可靠。

  • Godaddy dedicated server is faster

    我刚注意到 Godaddy 注册了一个 Tax ID EU826010755,开始对 perchase from the UK 征收 VAT,当前是15% (我在 2月份时仍是免 VAT的)。我不晓得这种财务变动是否伴随着基础设施的变动,可能这种变动已经发生。因为我注意到我的 Godaddy dedicated server 莫名其妙快了很多。