dev-master
9999999-devZF2 module for CMS content via LwcCmsPage module
by Timo Ziemann
cms content types cms content
Wallogit.com
2017 © Pedro Peláez
ZF2 module for CMS content via LwcCmsPage module
"require": {
"lwc/lwccmspage": "1.*", /* if not added yet */
"lwc/lwccmscontent": "1.*"
}
You may extend the LwcCmsContent module with your own content types. I'll describe an example use-case for a "person" content type here., (*1)
<?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'
)
)
)
);
Within your module, create the src/Acme/ContentType folder an put a Spokesperson.php file in it, like so:, (*2)
AbstractContentEntity class, the only thing you'll need to define is the getTypeId() method.
You may / have to define any getters/setters which you will need to display your content. However, while loading the contents, a ClassHydrator will be used to call the setters. So make sure your setters match the database columns. Underscores are allowed for the column names (those will be treated via camel-casing). Also take care not to specify typehints within your setters, as (basically) strings will be passed in from the database resultset.
#### Creating the view helper to display the model ####
Create the folder src/View/Helper and put a ContentSpokesperson.php in there, like so:
```php
getViewModel();
return $this->view->render($viewModel, array(
'person' => $content
));
}
}
```
The getViewModel() method is not needed, but it makes the file a bit cleaner / extendable (imho).
#### Adding the view script (ViewModel) ####
Create a view/acme-module/content directory and put a spokesperson.phtml in there, like so:
```php
escapehtml($person->getXYZ()); // use any methods from your model class here. ?>
</div>
Adding the ViewModel and the ViewHelper to your config
<?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',
)
)
);
ZF2 module for CMS content via LwcCmsPage module
cms content types cms content