lwc / lwccmscontent
此软件包最新版本(dev-master)没有可用的许可信息。
通过 LwcCmsPage 模块使用 ZF2 模块进行 CMS 内容管理
dev-master
2013-12-09 23:28 UTC
This package is not auto-updated.
Last update: 2024-09-23 15:51:11 UTC
README
Composer
"require": {
"lwc/lwccmspage": "1.*", /* if not added yet */
"lwc/lwccmscontent": "1.*"
}
ZF2 配置设置
- 将 "LwcCmsContent" 模块添加到您的 config/application.config.php 文件中
数据库设置
- 注意:请先设置 LwcCmsPage 模块!
- 将 data/table-init.sql 文件导入到您的数据库中。它将为存储 CMS 内容创建一些基本表。
- 该模块将提供一个名为 LwcCmsContent\DbAdapter 的 ServiceManager 别名。默认情况下,它指向一个 "dbAdapter" 服务。您可能需要根据应用程序的默认数据库适配器进行更改。
定义自己的内容类型
您可以通过自己的内容类型扩展 LwcCmsContent 模块。以下将描述一个 "person" 内容类型的示例用例。
在模块的配置文件中定义类型
<?php return array( 'lwccmscontent' => array( 'types' => array( // this array key will be inserted into the cms_content table, so // it should be unique within the whole application 'acme_spokesperson' => array( // or any other namespace within your module 'class_name' => 'Acme\ContentType\Spokesperson', // this view-helper will be used within the LwcCmsContent module // via __invoke(ContentEntityInterface $content), where $content // is an instance of your "class_name" 'view_helper' => 'contentSpokesperson' ) ) ) );
创建内容类型类(模型)
在您的模块中,创建 src/Acme/ContentType 文件夹并在其中放置一个 Spokesperson.php 文件,如下所示
<?php namespace Acme\ContentType; use LwcCmsContent\Model\ContentEntityInterface; use LwcCmsContent\Model\AbstractContentEntity; class Spokesperson extends AbstractContentEntity implements ContentEntityInterface { public function getTypeId() { return 'acme_spokesperson'; } }
通过扩展 AbstractContentEntity 类,您只需定义 getTypeId() 方法。您可能需要定义任何显示内容所需的 getters/setters。然而,在加载数据时,将使用 ClassHydrator 调用 setters。因此,请确保您的 setters 与数据库列匹配。列名允许使用下划线(这些将通过驼峰式命名法处理)。此外,请确保不要在 setters 中指定类型提示,因为(基本上)字符串将从数据库结果集中传递。
创建用于显示模型的视图助手
创建 src/View/Helper 文件夹并在其中放置一个 ContentSpokesperson.php 文件,如下所示
<?php namespace Acme\View\Helper; use Zend\View\Helper\AbstractHelper; use LwcCmsContent\View\Helper\RendererInterface; use LwcCmsContent\Model\ContentEntityInterface; class ContentSpokesperson extends AbstractHelper implements RendererInterface { /** * * @return string */ protected function getViewModel() { return 'content/spokesperson'; } /** * (non-PHPdoc) * * @see \LwcCmsContent\View\Helper\RendererInterface::__invoke() */ public function __invoke(ContentEntityInterface $content) { $viewModel = $this->getViewModel(); return $this->view->render($viewModel, array( 'person' => $content )); } }
getViewModel() 方法不是必需的,但它可以使文件更整洁/可扩展(个人意见)。
添加视图脚本(ViewModel)
创建 view/acme-module/content 目录并在其中放置一个 spokesperson.phtml 文件,如下所示
<div class="foobar"> <?php echo $this->escapehtml($person->getXYZ()); // use any methods from your model class here. ?> </div>
将 ViewModel 和 ViewHelper 添加到您的配置中
<?php return array( // ... other module stuff ... 'view_helpers' => array( 'invokables' => array( // the alias is important. // php namespace has to match the Helper class you just added above 'contentSpokesperson' => 'Acme\View\Helper\ContentSpokesperson' ) ), // ... even more stuff ... 'view_manager' => array( 'template_map' => array( // path could be any path, doesn't really matter. the array key is important 'content/spokesperson' => __DIR__ . '/../view/acme-module/content/spokesperson.phtml', ) ) );