首页 \ 问答 \ Zend Framework 2包括自定义库(Zend Framework 2 including custom library)

Zend Framework 2包括自定义库(Zend Framework 2 including custom library)

我的目录结构是这样的:

  • C:\工作区\ Zend公司
  • c:\ Workspaces \ Custom library

自定义库是一个共享库,在其他应用程序中使用。 它不使用命名空间,只使用旧式下划线。

我下载了ZF2-Restful-Module-Skeleton,我打算用它作为一个宁静的服务器。 在InfoController中我有这个代码:

namespace Main\Controller;

use Zend\Mvc\Controller\AbstractRestfulController;

class InfoController extends AbstractRestfulController
{
  public function getList()
  {
    $data = array(
        'phone'   => '+30123456789',
        'email'   => 'email@domain',
    );

    $Res = new CL_Res_Chain_Mutable();

    return $data;
  }
}

错误信息是:

致命错误:在C:\ Workspaces \ Zend \ module \ Main \ src \ Main \ Controller \ InfoController.php中找不到类'Main \ Controller \ CL_Res_Chain_Mutable'

显然,我需要将这个自定义库添加到我的Zend应用程序中,但我在这里“小”丢失了,我真的不知道该怎么做。 我用google搜索了几个解决方案,但它们似乎都不是这样的。

另外,我在文件夹c:\Workspaces\Custom library 2有另一个库,它有(在其他文件中)文件(类)D.php,我使用它像D :: dump($ data);

我怎样才能让它在我的Zend应用程序中工作?


My directory structure is like this:

  • c:\Workspaces\Zend
  • c:\Workspaces\Custom library

Custom library is a shared library, which is in use in other applications. It doesn't use namespaces, just old style underscores.

I downloaded the ZF2-Restful-Module-Skeleton which i intend to use as a restful server. In the InfoController I have this code:

namespace Main\Controller;

use Zend\Mvc\Controller\AbstractRestfulController;

class InfoController extends AbstractRestfulController
{
  public function getList()
  {
    $data = array(
        'phone'   => '+30123456789',
        'email'   => 'email@domain',
    );

    $Res = new CL_Res_Chain_Mutable();

    return $data;
  }
}

Error message is:

Fatal error: Class 'Main\Controller\CL_Res_Chain_Mutable' not found in C:\Workspaces\Zend\module\Main\src\Main\Controller\InfoController.php

Obviously, I need to add this custom library to my Zend application, but Im "little" lost here, I really don't know how to do this. I have googled couple solutions, but none of them seem to be like this.

Also, I have another library in folder c:\Workspaces\Custom library 2, which has (among other files) file(class) D.php, which I have used like D::dump($data);

How can I get it to work in my Zend application like that?


原文:
更新时间:2022-06-04 11:06

最满意答案

您需要从标题为动态字符串国际化的部分重新阅读开发指南。

该方法意味着您需要编写区域设置支持代码。 我们使用Dictionary类完成了这个。 提供语言环境支持的技巧是为每个语言环境提供一个字典。

步骤1-确保使用带有cookie的GWT module.gwt.xml的语言环境概念。 确保在加载gwt应用程序之前设置了cookie GWT_LOCALE。

<extend-property name="locale" values="en,ar,de" />
<set-property name="locale" value="en" />
<set-property-fallback name="locale" value="en" />
<set-configuration-property name="locale.cookie" value="GWT_LOCALE" />
<set-configuration-property name="locale.useragent" value="Y" />

步骤2-使用html脚本标记预先加载WidgetMessages.js或如果您希望按需获取此延迟,请使用RequestBuilder。 WidgetMessages.js的内容

var widget_messages_en = {
    "today" : "Today",
    "now" : "Now"
};

var widget_messages_ar= {
    "today"  : "۷ڤدجچ",
    "now"  : "چڤت"
}

var widget_messages_de= { 
    "today"  : "Today",
    "now"  : "Now"
}

步骤3-处理并将字典加载到本地散列映射中。

    private static Map<String, Dictionary> I18N_DICTIONARIES = new HashMap<String, Dictionary>();

    private static Dictionary createDictionary( String dictionaryName)
    {
            String moduleId = dictionaryName + "_messages_" + LocaleInfo.getCurrentLocale().getLocaleName();
            Dictionary dictionary = Dictionary.getDictionary( moduleId );
            I18N_DICTIONARIES.put( dictionaryName, dictionary );
            return dictionary;
    }

    public static String getI18NString(String dictionaryName, String stringToInternationalize )
    {
        Dictionary dictionary = I18N_DICTIONARIES.get( dictionaryName);
        if ( dictionary == null )
        {
            dictionary = createDictionary( dictionaryName);
        }
        String i18string = null;
        if ( dictionary == null )
            return stringToInternationalize;
        try
        {
            i18string = dictionary.get( stringToInternationalize );
        }
        catch ( Exception e )
        {
        }
        return i18string;
    }

注意 - 您可以尝试上述方法的几种变体来处理字符串到i18nstrings并在小部件上使用它们....


You need to re-read the the Dev Guide from the section titled Dynamic String Internationalization.

The approach means you need to code for locale support. We have done this using Dictionary class. The trick to provide locale support is to have a dictionary for each locale.

Step 1- Ensure you use locale concepts of GWT module.gwt.xml with cookie. Ensure cookie GWT_LOCALE is set before gwt application loads.

<extend-property name="locale" values="en,ar,de" />
<set-property name="locale" value="en" />
<set-property-fallback name="locale" value="en" />
<set-configuration-property name="locale.cookie" value="GWT_LOCALE" />
<set-configuration-property name="locale.useragent" value="Y" />

Step 2- Load WidgetMessages.js upfront using html script tags or Use RequestBuilder if you wish to fetch this lazily on demand. Contents of WidgetMessages.js

var widget_messages_en = {
    "today" : "Today",
    "now" : "Now"
};

var widget_messages_ar= {
    "today"  : "۷ڤدجچ",
    "now"  : "چڤت"
}

var widget_messages_de= { 
    "today"  : "Today",
    "now"  : "Now"
}

Step 3- Process and load the dictionaries into a local hashmap.

    private static Map<String, Dictionary> I18N_DICTIONARIES = new HashMap<String, Dictionary>();

    private static Dictionary createDictionary( String dictionaryName)
    {
            String moduleId = dictionaryName + "_messages_" + LocaleInfo.getCurrentLocale().getLocaleName();
            Dictionary dictionary = Dictionary.getDictionary( moduleId );
            I18N_DICTIONARIES.put( dictionaryName, dictionary );
            return dictionary;
    }

    public static String getI18NString(String dictionaryName, String stringToInternationalize )
    {
        Dictionary dictionary = I18N_DICTIONARIES.get( dictionaryName);
        if ( dictionary == null )
        {
            dictionary = createDictionary( dictionaryName);
        }
        String i18string = null;
        if ( dictionary == null )
            return stringToInternationalize;
        try
        {
            i18string = dictionary.get( stringToInternationalize );
        }
        catch ( Exception e )
        {
        }
        return i18string;
    }

Note - YOU CAN TRY Several variations of the above approach to process strings to i18nstrings and use them on widgets....

相关问答

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)