netglue / zf2-view-helpers
此包已被弃用,不再维护。未建议替换包。
提供各种有用视图辅助器的 ZF2 模块
0.1.2
2013-06-25 17:32 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.*
This package is auto-updated.
Last update: 2021-09-02 12:02:41 UTC
README
主要面向通用网站的视图辅助器集合。
安装
使用 composer 安装。在 packagist 上的包名为 netglue/zf2-view-helpers
,您的 ZF2 应用程序配置中的模块名为 NetglueViewHelpers
可用的辅助器
HeadIcons
此辅助器扩展了标准的 HeadLink 视图辅助器,添加了一些有用的快捷方式和将可接受的属性修改为包括 'sizes' 属性,以便用于 Apple touch 图标。
布局视图中的示例
$this->headIcons()->setWindowsIcon($this->basePath('favicon.ico'));
$this->headIcons()->setShortcutIcon($this->basePath('favicon.png'));
$this->headIcons()->addAppleTouchIcon($this->basePath('apple-touch-icon-144x144.png'), 144, 'image/png', true);
$this->headIcons()->addAppleTouchIcon($this->basePath('apple-touch-icon-114x114.png'), 114, 'image/png', true);
$this->headIcons()->addAppleTouchIcon($this->basePath('apple-touch-icon-72x72.png'), 72, 'image/png', true);
$this->headIcons()->addAppleTouchIcon($this->basePath('apple-touch-icon.png'), NULL, 'image/png', true);
echo $this->headIcons()->setSeparator("\n\t");
HeadOg
此辅助器扩展了 Zend\View\Helper\HeadMeta
并重写了 isValid()
,以便我们可以输出具有 HTML5 doctype 的页面的元属性。它提供了一些在视图中非常有用的方法。它有点丑陋,而且不做视频和其他许多有用的事情,但会逐步改进...
$this->headOg()->setOgTitle('Set a specific OG Title');
$this->headOg()->setOgDescription('And a specific description');
更易于操作 Facebook Admins 属性
$this->headOg()->setFacebookAdmins(array('ID1', 'ID2'));
$this->headOg()->addFacebookAdmin('ID3');
// would render <meta property="fb:admins" content="ID1,ID2,ID3">
为 og:type
和 og:site_name
提供便利的设置器/获取器
$this->headOg()->setOgType('website');
$this->headOg()->setOgSiteName('Foo');
var_dump($this->headOg()->getOgType()); // 'website'
轻松添加多个图像
// String url required at a bare minimum
$this->headOg()->addImage('http://example.com/image1.png');
// Specify any other valid image property
$this->headOg()->addImage(array(
'url' => 'http://example.com/image2.png',
'type' => 'image/png',
'width' => 100,
'height' => 100,
'secure_url' => 'https://example.com/image2.png',
));
默认情况下,自动将 head 标题和元描述应用到对应的 og:title
和 og:description
,以减少 FB Lint 错误/警告
由服务管理器构建,因此您可以设置所有页面的选项,并在视图中有选择地添加或修改仅重要的内容
return array(
'open_graph' => array(
// Setup any scalar property you like
'headProperties' => array(
'fb:page_id' => 'some id',
'og:site_name' => 'Foo',
'twitter:card' => 'summary',
// etc...
),
// Arrays of image specs, though as a full uri is required - you would probably add the images from your layout/view
'images' => array(
array(
'url' => 'http://example.com/image2.png',
'type' => 'image/png',
'width' => 100,
'height' => 100,
'secure_url' => 'https://example.com/image2.png',
),
),
// Options:
'useHeadTitleByDefault' => true, // Get contents of headTitle() helper and bung into a property
'useMetaDescriptionByDefault' => true, // The same for meta desc
'addOgUrlByDefault' => true, // Add the full uri of the current request to 'og:url' prop
),
);
待办事项
- 一如既往... 测试...
- OpenGraph 辅助器 - Zend 的 HeadMeta 辅助器不会渲染具有 HTML5 doctype 的
<meta property>
标签 - 虽然它们在我看来是完美的(W3C 验证器仍然允许它),也很有必要有一些具体的方法,例如 addFacebookAdmin() 等