I'm creating a dynamic Application in which the content is added through a CMS. Inside the CMS, I'm setting a db entry which states what module to use for each content page.
NodeId, ParentNodeId, Name_de, Name_en, ModuleName, foreignkey_ContentLinks,
in this table entries look as follows: 6, 1, Veranstaltung-21-02-2013, Event-21-02-2013, Events, 682
The entire tree should end up in my navigation (and perfectly also in my routing). I do not want to add it in some controller, because my Application consists of a whole bunch of Modules and I want to access that Info across all my Modules.
I already tried injecting it in the global.php, but to no avail because I can't my db adapter or any other important classes at that stage.
Any ideas or links to best practices?
Responding to your comment on @Crisp's answer, and for future googlers, I'll explain how to do something similar for routing.
Typically you would want to create a custom router that can match URLs to the pages in your database, similarly to the standard
Segment
router. To do this, you will have to implement theZend\Mvc\Router\RouteInterface
interface. For example:You could then register this route as an invokable for the
RoutePluginManager
in your module configuration:Then, you can create a new route (just as you would for any other route) with type
Cms
. The route plugin manager will create your route instance, and sinceCmsRoute
implementsServiceLocatorAwareInterface
, the plugin manager will inject itself in the route. In turn, the plugin manager has the main service manager set, so that you can get the database table from there!Of course you can match on page ID, but if you have a hierarchical structure, it's nicer to reflect that in your URLs. I would therefore recommend adding a
route
field to the database schema and match on that, beginning with the tree root and working down.The navigation containers are composed by factory classes. The easiest approach is to write your own factory and have the
getPages()
method fetch pages from a database instead of from config. If you extend from the AbstractNavigationFactory you only need to write a couple of methods.Add the factory to the service manager, just like you would for other containers
And use it with the navigation view helpers in the same way