为什么找不到IntlDateFormatter?

时间:2015-04-09 14:57:45

标签: php zend-framework2 view-helpers

加载了php-intl扩展 因为我可以在视图脚本中使用IntlDateFormatter :: SHORT而没有任何问题。

我的ViewHelper中的

<?php

namespace Common\View\Helper;

use Zend\View\Helper\AbstractHelper;

class DateFormat extends AbstractHelper {

    public function __invoke($dateField) {
        $dateFormatter=$this->getView()->plugin('dateformat');        
        return $dateFormatter(strtotime($dateField),       IntlDateFormatter::SHORT);  
    }
}
?>

我收到错误

  

致命错误:找不到类'Common \ View \ Helper \ IntlDateFormatter'   C:\ TEMP \ zf2ad \客户端\模块\ COMMON \ SRC \ COMMON \查看\助手\ DateFormat.php   在第12行

请告知

1 个答案:

答案 0 :(得分:3)

由于您在命名空间上下文中工作,因此它会在实际的命名空间Common\View\Helper中查找该类。如果它在全局命名空间中,则必须在类前添加反斜杠。

return $dateFormatter(strtotime($dateField), \IntlDateFormatter::SHORT);