个人工具
登录
查看“Zope3宝典/添加视图”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Zope3宝典/添加视图”的源代码
来自Ubuntu中文
←
Zope3宝典/添加视图
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==== 14.1.3 (c) Registering the View(14.1.3 (c) 注册视图) ==== The final task is to register the new view using ZCML. Open the configuration file in the browser sub-package and add the following lines:<br>最后的工作就是用ZCML注册这个新的视图。在browser目录中打开配置文件(configure.zcml)并添加如下各行: <pre><nowiki> 1 <page 2 name="details.html" 3 for="book.messageboard.interfaces.IMessage" 4 class=".message.MessageDetails" 5 template="details.pt" 6 permission="zope.Public" 7 menu="zmi_views" title="Preview"/> </nowiki></pre> * Line 1: The browser:page directive registers a single page view.<br>第1行:browser:page指令注册一个单独的页面视图。<br><br> * Line 2: The name attribute specifies the name as which the view will be accessible in the URL: <br>第2行:name属性指定了这个视图,可通过如下地址访问:<br> <pre><nowiki> http://localhost:8080/board/message1/@@details.html </nowiki></pre><br>The name attribute is required.<br>name属性是必需的。<br><br> * Line 3: The for attribute tells the system that this view is for IMessage objects. If this attribute is not specified, the view will be registered for Interface, which means for all objects.<br>第3行:For属性将告诉系统这个视图是针对Imessage对象。如果属性没有被指定,表明视图将注册的接口适合全部对象。<br><br> * Line 4-5: Use the just created <code><nowiki>MessageDetails</nowiki></code> class and details.pt page template for the view; for this page details.pt will be rendered and uses an instance of <code><nowiki>MessageDetails</nowiki></code> as its view.<br>第4-5行:为该视图创建<code><nowiki>MessageDetails</nowiki></code>类和details.pt页面模板;details.pt页将作为视图被提供和用做<code><nowiki>MessageDetails</nowiki></code>的实例。<br><br>Note that not all views need a supporting view class; therefore the class attribute is optional.<br>注意不是所有的视图都需要一个视图类来支持,因此该类属性是可选的。<br><br>While you will usually specify a page template for regular pages, there are situations, where you would prefer a view on an attribute of the Python view class. In these cases you can specify the attribute attribute instead of template. The specified attribute/method should return a unicode string that is used as the final output.<br>通常您为一个规则的页面指定页面模板时,您也许宁愿有视图基于Python视图类属性的情形存在。这样的话,您能指定代替模板的属性。指定的属性/方法应该以unicode字符串的形式返回并最终输出。<br><br> * Line 6: The permission attribute specifies the permission that is required to see this page. At this stage we want to open up the details pages to any user of the site, so we assign the zope.Public permission, which is special, since every user, whether authenticated or not, has this permission.<br>第6行:Permission属性指定了查看该页面被要求的权限。现在我们想设置任何该站点的用户都有打开详细页的权限,于是我们设定了zope.Public权限。<br><br> * Line 7: In order to save ourselves from a separate menu entry directive, we can use the menu and title attribute to tell the system under which menu the page will be available. In this case, make it a tab ( zmi_views menu) which will be called “Preview”.<br>第7行:为了避免使用另外单独的菜单条目指令,我们可以利用菜单和名称属性来告知系统,网页应当隶属于哪一个菜单。此处我们使用一个标签(zmi_views menu),并将其命名为Preview(预览)。 All you need to do now is to restart Zope, add a Message content object (if you have not done so yet) and click on it. The “Preview” tab should be available now. Note that you will have no “Parent” entry, since the message is not inside another one.<br>现在您必须重新启动Zope,如果您以前没有添加一个消息对象的话请单击添加它。"Preview" tab菜单条目现在应该有效。假如这个消息没有包含在另一个消息里面,请注意界面上将没有"Parent"条目显示。 To see a “Parent” entry, add another message inside the current message by using the “Contents” view. Once you added the new message, click on it and go to the Details view. You should now see a “Parent” entry with a link back to the parent message.<br>为了在界面上看到"Parent"条目,需要使用"Contents"视图在当前消息下面新增另一条消息。现在您应该能看到一个能够链接到父消息的"Parent"条目。
返回至
Zope3宝典/添加视图
。