312008
 

这实际上是由于 PHP 不允许在析构函数中抛出异常造成的,关于这个 issue 我已经提交到 issues 上:

http://framework.zend.com/issues/browse/ZF-2534

暂时没有想到好的解决方法。通常执行到析构函数时,邮件已经正确发出。所以最不济的方法就是用try…catch… 捕获异常,并忽略掉。

如下:

public function __destruct()
{

     try

    {
         if ($this->_connection instanceof Zend_Mail_Protocol_Smtp)

        {

            $this->_connection->quit();

            $this->_connection->disconnect();

         }

    catch(Zend_Exception $e)

    {

    }
}

312008
 

Zend_Mail 中文主题乱码的原因主要是在编码后超长内容的设置上出现问题。

已经提交到 issues 上了:

http://framework.zend.com/issues/browse/ZF-2532

如果有朋友遇到主题乱码,可以尝试使用更短的主题。或者使用我在 issrues 上提到的方法临时解决一下。

据我所知,这个 bug 在 1.5 的 perview 版本中依然存在。

122008
 
看到邮件列表上说,于 1 月 22 日冻结代码,计划 1 月 24 日正式发布。
增加了不少新的功能,正式发布的时候还可能有更多的一些功能:
  * Zend_Auth_Adapter_Ldap
  * Zend_Build/Zend_Console
  * Zend_Controller additional action helpers
    * ContextSwitch and AjaxContext
    * Json
    * AutoComplete
  * Zend_Form
  * Zend_InfoCard
  * Zend_Layout
  * Zend_OpenId
  * Zend_Search_Lucene improvements:
    * wildcard search
    * date range search
    * fuzzy search
    * Lucene 2.1 index file format support
  * Zend_View enhancements:
    * actions
    * partials
    * placeholders
  * Zend_Pdf UTF8 support
  * New Zend_Service consumables (final list TBD)
  * A whole lotta bug fixes and documentation improvements

 

十二 122007
 

系统运行要求

  • PHPUnit 3.1.x

PHPUnit 的安装

参考:http://www.phpunit.de/pocket_guide/3.1/en/installation.html

建议使用 Pear 方式安装。 Pear 包的安装请参考http://pear.php.net/manual/en/installation.php

测试用例的编写

参考:http://www.phpunit.de/pocket_guide/3.1/en/writing-tests-for-phpunit.html

应注意,在本框架使用中实际无需在测试用例加载任何文件。

配置文件的设置

<?xml version=’1.0′ encoding=’UTF-8′ ?>
<AllTests>
<TestSuite>
<name>FoobarTest</name>
<require>AnotherFoobar.php</require>
</TestSuite>
<Test>
<class>Foo_Bar_AllTest</class>
<method>suite</method>
<require>/home/foo/bar/AnotherLib.php</require>
</Test>
</AllTests>

  • TestSuite? 标签指定需要加载的单元测试用例。name 标签指定测试用例名(类名)。
  • Test 为一组单元测试用例。class 标签指定测试用例组类名,method 标签指定该类返回 PHPUnit_Framework_TestSuite 实例的类方法。
  • 类名的命名应遵从 Zend Framework 的命名规则,即下划线分隔文件路径作为类名。如:类文件存放于 Foo/Bar/AllTest.php,则类对应为 class Foo_Bar_AllTest {…}。
  • 测试用例和测试用例组都将自动加载。保存于 include path 下,符合 Zend Framework 类命名规范的类也都将自动加载(使用 Zend_Loader::registerAutoload() 方法)。若还需加载其他文件,应指定 require 标签,require 标签内容为待加载文件的完整路径或相对于测试目录(tests)的相对路径。

 

执行测试

  1. php 的 cli 程序应在系统 PATH 中。
  2. PHPUnit 的执行程序应在系统 PATH 中(Windows 下为 PHPUnit.bat,Linux 下为 PHPUnit.sh)。

All Tests

进入测试框架所在目录,执行 php AllTests?.php。

One Test

进入测试框架所在目录,执行 php OneTest?.php Test_Name。

改进方向

  • 迭代测试用例,子集测试用例可作为独立的测试执行,亦可通过配置文件加载入上级测试执行。
  • 通过配置文件自动生成测试用例框架,编写测试时只需要填写相应测试断言。
十二 032007
 

发现不少人对此有迷惑,所以有通常的做法:设置 noViewRender,然后将 ajax 调用时的返回数据直接输出于 controller 中。

个人以为,这种做法不是不可以。但是在 Zend Framework 中这样使用,就有违 MVC 的分离原则。controller 不应该区分显示到客户端的是页面还是 json 或者 xml。

下面是我的做法,仅供参考。部分调用了 ninny project 中封装的功能凑合看吧:

———————–view script: index.php—————————

<?php echo $this->jquery();?>
<script language="javascript">
// jquery ajax 的 json
$().ready(
function(){
$("#load").click(
function() {
$.getJSON("/foobar/index/ajax",function(data){
$("#title").html(data.title);
content = "";
$.each(data.content, function(i, line){
content += line + "<br/>";
});
$("#content").html(content);
});
});
});
</script>
<div id="title"></div><div id="content"></div><input type="button" id="load" value="Load"/>
-----------------------view script: ajax.php---------------------------
<?php
// Zend_Json 处理输出的对象,如果这里不使用 Zend_Json,可使用其他编码器将 php 对象进行编码输出。
// 这样在需要修改输出类型时,仅需要修改视图部分。而不涉及数据模型或控制器。
echo Zend_Json::encode($this->content);
?>

———————–action controller: Foobar_IndexController.php—————————

<?php
class Foobar_IndexController extends Ifang_Controller_Action
{
public function indexAction()
{
}
public function ajaxAction()
{
$foobar = array(
'title' => 'This is a test!',
'content' => array(
'0' => 'This is the first line!',
'1' => 'This is the second line!',
'2' => 'This is the last line!',
),
);
// 传递一个普通的 php 对象(变量)到视图。
$this->view->content = $foobar;
}
}
十一 152007
 

My codes is:

public function testGetTextTw()

{

    $t = new Zend_Translate(‘gettext’, ‘./_locale/’, ‘zh_TW’);

    $this->assertEquals(‘n2′, $t->_(‘New’));

}

public function testGetTextCn()

{

    $t = new Zend_Translate(‘gettext’, ‘./_locale/’, ‘zh_CN’);

    $this->assertEquals(‘n1′, $t->_(‘New’));

}

But, the testGetTextCn() go into fail: expected string ‘n1′ but got string ‘n2′.

So, I read the codes in Zend_Translate_Adapter::__construct().
the param variable $local was covered by an other value.

I made this patch:

zend_translate_adapter patch

Now, it works fine!

The issue and the patch have been submited to issue tracker:

framework.zend.com/issues/browse/ZF-2205

 

272007
 

下载 9月2日的讲义幻灯和代码示例。

在线演示:www.i-fang.com/php/lucene4php/search.php

内容如下:

  Continue reading »

212007
 

Zend_Application – a general-purpose bootstrap class, optionally driven
by a configuration file.
http://framework.zend.com/wiki/x/K48

Zend_Application – 通用的 bootstrap 类,通过配置文件设置选项。

貌似,跟 ninny project 的 IfangSite 类异曲同工。恩,是不是以后我可以从 Zend_Application 继承 IfangSite,希望迁移工作不要太麻烦。Zend_Application 配置文件的格式是固定的,如果跟我现在设计的差别很大,那就糗了。-_-!

202007
 

www.oracle.com/technology/global/cn/pub/articles/oracle_php_cookbook/mckay_objects.html

虽然是 05 年的了,但现在看还是不错的一篇文章。应该也可以用于 mysql。

162007
 

许多人说 Zend_DB_Select 是一个丑陋的实现,同时是完全没有必要的。那么我想谈一下我的想法,为什么我们需要 Zend_Db_Select。 Continue reading »