Last active
October 31, 2016 16:16
-
-
Save bitkorn/90bbb11bade50f91ba6103f89a2070c5 to your computer and use it in GitHub Desktop.
In ZF2 Controller: Get the route from URL and look at database for content to show it in view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the route from URL and look at database for content to show it in view. | |
* @return ViewModel | |
*/ | |
public function routesCmsAction() | |
{ | |
$routeMatch = $this->serviceLocator->get('Application')->getMvcEvent()->getRouteMatch(); | |
$routeName = $routeMatch->getMatchedRouteName(); | |
$router = $this->getEvent()->getRouter(); | |
$route = substr($router->assemble([], array('name' => $routeName)), 1); // cut the slash | |
$contentArr = $this->getContentTable()->getContentByRoute($route); | |
$metaTitle = ''; | |
$metaDescription = ''; | |
$metaKeywords = ''; | |
$contentString = '<div class="startcontent">'; | |
if (!empty($contentArr)) { | |
$metaTitle = $contentArr['content_meta_title']; | |
$metaDescription = $contentArr['content_meta_description']; | |
$metaKeywords = $contentArr['content_meta_keywords']; | |
if (!empty($contentArr['content_title'])) { | |
$contentString .= '<h4>' . $contentArr['content_title'] . '</h4>'; | |
} | |
$contentString .= $contentArr['content']; | |
} | |
$contentString .= '</div>'; | |
return new ViewModel([ | |
'textarea' => null, | |
'content' => $contentString, | |
'meta_title' => $metaTitle, | |
'meta_description' => $metaDescription, | |
'meta_keywords' => $metaKeywords, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment