个人工具
登录
查看“Zope3宝典/改变尺寸信息”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Zope3宝典/改变尺寸信息”的源代码
来自Ubuntu中文
←
Zope3宝典/改变尺寸信息
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=== 17.3 Step III: Registration(17.3 步骤 III:注册) === Now we register the adapter in messageboard/configure.zcml using the following ZCML directive:<br>现在我们使用下面的ZCML指令在messageboard/configure.zcml中注册适配器: <pre><nowiki> 1 <adapter 2 factory=".message.MessageSized" 3 provides="zope.app.size.interfaces.ISized" 4 for=".interfaces.IMessage" 5 /> </nowiki></pre> The zope:adapter is the way to register global adapters via ZCML. The factory attribute allows you to specify a list of factories (usually only one is specified) that are responsible for creating an adapter instance that takes an object implementing the interface specified in the for attribute and providing the interface specified in provides. All of these three attributes are mandatory.<br>zope:adapter是通过ZCML注册全局适配器的方法。工厂(factory)属性允许您指定一连串的工厂(通常只有一个被指定),专门负责创建适配器实例。在for属性里指定对象实现的接口,在provides里指定提供的接口。所有这三个属性都是强制性的。 For our case, we basically say that an instance of the `MessageSized` class provides an ISized interface for objects implementing IMessage.<br>对于我们的范例,我们基本上说 `MessageSized` 类的实例提供一个 ISized 接口给实现 IMessage 的对象。 The directive also supports two optional arguments. We can also specify a permission. The adapter will be only available to the principal, if the principal has the specified permission. If no permission is specified, everyone can access the adapter. The other optional argument of the directive is the name attribute that specifies the name of the adapter. Using names, we can specify multiple adapters from one interface to another.<br>指令也支持两个可选择的参数。我们也能指定一个许可。如果主体已经指定了许可,适配器将只对主体可用。如果没有许可指定,每个人都能访问该适配器。指令的其它可选参数是name属性,该属性指定了适配器的名称。使用名称,我们能从一个接口到另一个接口指定多个适配器。 That’s it! Restart Zope 3 and see for yourself. Note how we did not need to touch any existing Python code to provide this functionality.<br>这就是本章所有的内容了。重新启动Zope 3 并且自个儿瞧瞧。 注意我们不需要接触任何已经存在的Python代码就可以提供这些功能了。 Exercises(练习) *** Write an ISized adapter for `IMessageBoard` that outputs xmessages as the displayable size.<br>为 `IMessageBoard` 写一个 ISized 适配器输出xmessages(显示大小)。
返回至
Zope3宝典/改变尺寸信息
。